![]() |
[Hackerrank] Solution of Birthday Chocolate in JavaScript |
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 birthday(s, d, m) { | |
let result = 0; | |
for(let i = 0; i < s.length - (m - 1); i++) { | |
if (s.slice(i, i + m).reduce((r, v) => r + v, 0) === d) { | |
result++; | |
} | |
} | |
return result; | |
} |