r/CodingHelp • • Jul 02 '21

[Javascript] Problem with JavaScript code

Post image
62 Upvotes

19 comments sorted by

View all comments

4

u/Cheesybread4ever Jul 02 '21

So I want this function to accept an array of nine numbers, and I want it to return true if all the numbers are unique. I’m assuming all the numbers will be 1-9. For some reason this keeps returning false when I pass an array that should return true. You can also ignore the console log I was trying to debug with it.

1

u/Roguewind Jul 02 '21

Under the assumption that the myArray will always be exactly 9 single digit numbers, just pass it into a set and check the size of the set

const includes1to9(myArray) => { return (new Set(myArray).size === 9) }

Set takes an array and creates a Set object with unique values.