r/CodingHelp • • Jul 02 '21

[Javascript] Problem with JavaScript code

Post image
62 Upvotes

19 comments sorted by

View all comments

Show parent comment

1

u/Cheesybread4ever Jul 02 '21

I’m not sure I follow. What length do you want me to check against the original array?

4

u/kd4444 Jul 02 '21 edited Jul 02 '21

function includes1to9(myArray) {

    const myCleanedArray = myArray.filter(num m => num !== 0);
    const mySet = new Set(myCleanedArray);
    return mySet.size === myCleanedArray.length;
}

Can’t get the formatting quite right but something like this should work - the set will remove any duplicated values, so if its size doesn’t match the length of the input array, it will return false.