Skip to content

Instantly share code, notes, and snippets.

@alexko30
Last active April 30, 2018 22:40
Show Gist options
  • Save alexko30/c184c792200236500446ee39400b321b to your computer and use it in GitHub Desktop.
Save alexko30/c184c792200236500446ee39400b321b to your computer and use it in GitHub Desktop.
sumTill
function sumTill(start, till) {
if(start < till && till > 0) {
let step = start;
let result = start;
let resultArray = [];
resultArray.push(result);
for (let i = 0; i < till; i++) {
result += step;
if (result < till) {
resultArray.push(result);
}
}
let sum = 0;
for (let i = 0; i < resultArray.length; i++) {
sum += resultArray[i]
}
console.log(sum);
}
else
console.log('wrong number');
}
sumTill(4, 25); // 4 + 8 + 12 + 16 + 20 + 24 = 84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment