Skip to content

Instantly share code, notes, and snippets.

@alexko30
Created May 16, 2018 18:43
Show Gist options
  • Save alexko30/a254ca6baf28bb418b626bc3896bc50b to your computer and use it in GitHub Desktop.
Save alexko30/a254ca6baf28bb418b626bc3896bc50b to your computer and use it in GitHub Desktop.
ifDivided.js
function ifDivided(arr, divider) {
let flag = false;
for (let i = 0; i < arr.length; i++) {
if (arr[i] % divider == 0) {
flag = true;
break;
}
}
if (!flag) {
for (let i = 0; i < arr.length; i++) {
if (!flag) {
for (let j = i; j < arr.length; j++) {
if ((arr[i] + arr[j + 1]) % divider == 0) {
flag = true;
break;
}
}
} else
break;
}
}
console.log(flag);
}
ifDivided([1,2,5,3,4,5],10); // true
ifDivided([1,3,4,7,6],9); // true
ifDivided([8,5,3,9],7); // true
ifDivided([8,5,3],7); // false
ifDivided([5,8,3,5,1,5],12); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment