Skip to content

Instantly share code, notes, and snippets.

@Shaxadhere
Last active August 12, 2022 19:19
Show Gist options
  • Save Shaxadhere/b227a3042014fcb72135e8476af9685f to your computer and use it in GitHub Desktop.
Save Shaxadhere/b227a3042014fcb72135e8476af9685f to your computer and use it in GitHub Desktop.
const a = [1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
let count = 0
let _count = []
a.forEach((item, index)=> {
if(item==1){
count = count + 1
if(index==a.length-1) _count.push(count)
}
else{
_count.push(count)
count =0
}
})
console.log(Math.max(..._count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment