Skip to content

Instantly share code, notes, and snippets.

@pinkmomo027
Created June 14, 2018 22:21
Show Gist options
  • Save pinkmomo027/e945cde260a5c1b745e46498104f8353 to your computer and use it in GitHub Desktop.
Save pinkmomo027/e945cde260a5c1b745e46498104f8353 to your computer and use it in GitHub Desktop.
stock span
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]));
@pinkmomo027
Copy link
Author

[ 1, 1, 1, 2, 1, 4, 6 ]
[Finished in 0.1s]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment