Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

using slice and reduce together in javascript

//subdivision Array
function birthday(s, d, m) {
    let count = 0
    const length = s.length - m 
    for(let i=0;i<=length;i++) {
        if(s.slice(i,i+m).reduce((a,b) => a+b)=== d) {
            count++
        }
    }
    console.log(count)
}
birthday([1,2,1,3,2],3,2)
 
PREVIOUS NEXT
Tagged: #slice #reduce #javascript
ADD COMMENT
Topic
Name
1+3 =