Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianbiring1/8b349bfb469f83dd15f54a5881976654 to your computer and use it in GitHub Desktop.
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.
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