-
-
Save xmanemran/e87f6467f81f7c1a37f7d86812e8f848 to your computer and use it in GitHub Desktop.
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
console.clear(); | |
const arr = [2, 1, 5, 2, 3, 2]; | |
const s = 8; | |
let found = false; | |
for(let i = 1; i <= arr.length; i++){ | |
let sum = 0; | |
let number = 0; | |
for(let j = 0; j < arr.length; j++){ | |
sum += arr[j]; | |
number++; | |
if(sum >= s){ | |
console.log(number); | |
found = true; | |
break; | |
} | |
if(number == i){ | |
sum = 0; | |
number = 0; | |
} | |
if(i < 1){ | |
sum += arr[j]; | |
number++; | |
} | |
} | |
if(found){ | |
break; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment