Created
February 23, 2022 11:06
-
-
Save Spirecool/6f22d983eb9c13957e6f9c8d05979865 to your computer and use it in GitHub Desktop.
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
function getNote(counter, notes, higher, lower) { | |
if (!higher && !lower) { | |
higher = notes[counter]; | |
lower = notes[counter]; | |
counter++; | |
} | |
if (counter < notes.length) { | |
higher = higher > notes[counter] ? higher : notes[counter]; | |
lower = lower < notes[counter] ? lower : notes[counter]; | |
counter++; | |
return getNote(counter, notes, higher, lower) | |
} else { | |
return {higher, lower} | |
} | |
} | |
const notes = [10, 20, 15, 17, 8, 5, 12, 4]; | |
console.log(getNote(0, notes, null, null)) // {heigher: 20, lower: 4} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment