Created
October 11, 2021 11:31
-
-
Save Stefanacef/c5fd2f0e9cf9c14c05166e8efe61e7f3 to your computer and use it in GitHub Desktop.
Solution for "Subarray Division" in Hackerrank
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
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