duplicated solutions in loops to match themes
This commit is contained in:
@@ -1,3 +1,11 @@
|
|||||||
function sum() {
|
function sum() {
|
||||||
return arguments.reduce((total, num) => total + num, 0);
|
return arguments.reduce((total, num) => total + num, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sum() {
|
||||||
|
let total = 0;
|
||||||
|
for (let i = 0; i < arguments.length; i++) {
|
||||||
|
total += arguments[i];
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,13 @@
|
|||||||
sum = function(...args) {
|
sum = function(...args) {
|
||||||
return args.filter(num => num % 2 !== 0).reduce((acc, num) => acc + num, 0);
|
return args.filter(num => num % 2 !== 0).reduce((acc, num) => acc + num, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sum = function(...args) {
|
||||||
|
let total = 0;
|
||||||
|
for (let num of args) {
|
||||||
|
if (num % 2 !== 0) {
|
||||||
|
total += num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
@@ -1,3 +1,12 @@
|
|||||||
sum = (...args) => {
|
sum = (...args) => {
|
||||||
return args.filter(num => num % 2 !== 0).reduce((acc, num) => acc + num, 0);
|
return args.filter(num => num % 2 !== 0).reduce((acc, num) => acc + num, 0);
|
||||||
}
|
}
|
||||||
|
sum = (...args) => {
|
||||||
|
let total = 0;
|
||||||
|
for (let i = 0; i < args.length; i++) {
|
||||||
|
if (args[i] % 2 !== 0) {
|
||||||
|
total += args[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user