Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Stefanacef/c5fd2f0e9cf9c14c05166e8efe61e7f3 to your computer and use it in GitHub Desktop.
Save Stefanacef/c5fd2f0e9cf9c14c05166e8efe61e7f3 to your computer and use it in GitHub Desktop.
Solution for "Subarray Division" in Hackerrank
let num = s;
let nums = [];
let count = 0;
const s = [4];
const d = 4;
const m = 1;
function birthday(s, d, m) {
let num = s;
let nums = [];
let count = 0;
const add = (arr) => arr.reduce((a, b) => a + b, 0);
for (let i = 0; i < s.length; i++) {
let arrayElement = num.slice(0 + i, m + i);
nums.push(arrayElement);
}
if(num.length===1 && num[0]===d){
count++;
}else{
nums.forEach((el) => {
if (add(el) === d) {
count++;
}
});
}
return count;
}
console.log(birthday(s, d, m));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment