Skip to content

Bug Report for three-integer-sum #4340

@agogte

Description

@agogte

Bug Report for https://neetcode.io/problems/three-integer-sum

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

let newArr = Array.from(nums);

This line for some reason considers newArr as NOT an array. The error it gives me is -

TypeError: arr.sort is not a function
at /box/script.js:113:40
at Array.map ()
at processInput (/box/script.js:113:25)
at ReadStream. (/box/script.js:89:9)
at ReadStream.emit (node:events:513:28)
at endReadableNT (node:internal/streams/readable:1359:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

The code:

threeSum(nums) {
        let res = [];
        for(let i = 0; i < nums.length; i++){
            let newArr = Array.from(nums);
            console.log("nums instanceof Array:", nums instanceof Array);
            console.log("newArr instanceof Array:", newArr instanceof Array);

            let target = 0 - nums[i];
            newArr.splice(i, 1);
            newArr.sort((a,b) => a -b);
            ......

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions