Skip to content

Instantly share code, notes, and snippets.

@Spirecool
Created February 23, 2022 11:06
Show Gist options
  • Save Spirecool/6f22d983eb9c13957e6f9c8d05979865 to your computer and use it in GitHub Desktop.
Save Spirecool/6f22d983eb9c13957e6f9c8d05979865 to your computer and use it in GitHub Desktop.
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