Created
June 7, 2021 08:06
-
-
Save Pierre-M/3f66029ea2bb8f469e0e8ca6192ee169 to your computer and use it in GitHub Desktop.
Weekly question from Cassidy Williams newsletter (07/06/2021)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const lonelyNumber = (...numbers) => { | |
if (numbers.length !== 3) { | |
return console.warn('You must provide 3 numbers.'); | |
} | |
if (numbers.every((item, index, items) => item === items[0])) return 1; | |
const lonelyNumbers = numbers.filter((item, index, items) => { | |
return items.filter(i => i === item).length === 1; | |
}) | |
if (lonelyNumbers.length === 1) return lonelyNumbers[0]; | |
return numbers.reduce((acc, curr) => { | |
return acc * curr; | |
}, 1) | |
} | |
console.log(lonelyNumber(...process.argv.slice(2).map(arg => parseInt(arg, 10)))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment