Created
June 14, 2018 22:21
-
-
Save pinkmomo027/e945cde260a5c1b745e46498104f8353 to your computer and use it in GitHub Desktop.
stock span
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 stockSpan(array) { | |
let answer = []; | |
array.forEach((stock, index) => { | |
let count = 1; | |
for(let i = index - 1; (i >= 0) && (array[i] <= stock); i--) { | |
count++; | |
} | |
answer.push(count); | |
}); | |
return answer; | |
} | |
console.log(stockSpan([100, 80, 60, 70, 60, 75, 85])); |
Author
pinkmomo027
commented
Jun 14, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment