Created
October 22, 2019 13:29
-
-
Save daubattu/c15a8849b509d01c54a5c21fe133ebc6 to your computer and use it in GitHub Desktop.
[Hackerrank] Solution of Birthday Chocolate in JavaScript
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 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome! Thanks! 🙂