Forked from daubattu/hackerrank_solution_of_birthday_chocolate_in_javascript.js
Created
April 14, 2022 01:55
-
-
Save caot/17387aba8ee4b933342537d7a780f02d 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; | |
} |
Author
caot
commented
Apr 14, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment