Last active
August 25, 2020 21:07
-
-
Save jaquinocode/406155626469d756400f91ef173bb784 to your computer and use it in GitHub Desktop.
Get the index of the minimum number in the array. For 2nd one, reduce replaces python's min w/ a key since we don't have that in js.
This file contains hidden or 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 indexOfMin = numbers => { | |
return numbers.indexOf(Math.min(...numbers)) | |
} |
This file contains hidden or 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 indexOfMin = numbers => { | |
if(!numbers.length) return -1 | |
return numbers.reduce((minI, curr, i) => curr < numbers[minI] ? i : minI, 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment