Skip to content

Instantly share code, notes, and snippets.

@jaquinocode
Last active August 25, 2020 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaquinocode/406155626469d756400f91ef173bb784 to your computer and use it in GitHub Desktop.
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.
const indexOfMin = numbers => {
return numbers.indexOf(Math.min(...numbers))
}
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