simplified the solution by using Sets and corrected the answer to correspond the assignment
const lines = ['1,2,3,4,5,6', '2,4,6,7,8,9,10', '1,2,3,4,5,6,8'] function FindIntersection(lines) { const getSet = line => new Set(line.split(',').map(number => parseInt(number))) const [firstSet, ...otherSets] = lines.map(getSet) const result = [...otherSets.reduce((lastSet, set) => new Set([...set].filter(number => lastSet.has(number))), firstSet)] return result.length > 0 ? result : 'false' } console.log(FindIntersection(lines)) // outputs: [2,4,6]
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
simplified the solution by using Sets and corrected the answer to correspond the assignment