Skip to content

Instantly share code, notes, and snippets.

@cihat
Created November 15, 2020 22:40
Show Gist options
  • Save cihat/b57f54128e291ca3a4d346dcdd2041fd to your computer and use it in GitHub Desktop.
Save cihat/b57f54128e291ca3a4d346dcdd2041fd to your computer and use it in GitHub Desktop.
function sum() {
var result = 0,
i = 0,
len = arguments.length;
while (i < len) {
result += arguments[i];
i++;
}
return result;
}
console.log(sum(1, 2)); // 3
console.log(sum(3, 4, 5, 6)); // 18
console.log(sum(50)); // 50
console.log(sum()); // 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment