Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save daubattu/c15a8849b509d01c54a5c21fe133ebc6 to your computer and use it in GitHub Desktop.
Save daubattu/c15a8849b509d01c54a5c21fe133ebc6 to your computer and use it in GitHub Desktop.
[Hackerrank] Solution of Birthday Chocolate in JavaScript
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;
}
@musobekmadrimov
Copy link

Awesome! Thanks! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment