Last active
August 31, 2022 08:10
-
-
Save christianbiring1/8b349bfb469f83dd15f54a5881976654 to your computer and use it in GitHub Desktop.
Two children, Lily and Ron, want to share a chocolate bar. Each of the squares has an integer on it.
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) { | |
// Write your code here | |
let result = 0; | |
for(let i = 0; i < s.length; 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