Skip to content

Instantly share code, notes, and snippets.

@xmanemran
Created October 9, 2019 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xmanemran/e87f6467f81f7c1a37f7d86812e8f848 to your computer and use it in GitHub Desktop.
Save xmanemran/e87f6467f81f7c1a37f7d86812e8f848 to your computer and use it in GitHub Desktop.
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