Last active
October 21, 2019 13:40
-
-
Save steven-mercatante/8bce511acea01b4e6de92e149775c7ab to your computer and use it in GitHub Desktop.
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
function subLength(nbs) { | |
if (nbs.length === 0) { | |
return 0 | |
} | |
let highestCounter = 1 | |
let counter = 1 | |
for (let i = 1; i < nbs.length; i++) { | |
if (nbs[i] > nbs[i - 1]) { | |
counter += 1 | |
if (counter > highestCounter) { | |
highestCounter = counter | |
} | |
} else { | |
counter = 1 | |
} | |
} | |
return highestCounter | |
} | |
console.log(subLength([13, 35, 1, 5, 40, 86])) // 4 | |
console.log(subLength([0, 1, 2, 3, 13, 35, 1, 5, 40, 86])) // 6 | |
console.log(subLength([0, 0, -1, 2, 10, 5])) // 3 | |
console.log(subLength([])) // 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment