diff --git a/lectures/lec5/p1/task6.js b/lectures/lec5/p1/task6.js index 25da7ac..1bf9532 100644 --- a/lectures/lec5/p1/task6.js +++ b/lectures/lec5/p1/task6.js @@ -1,3 +1,11 @@ function sum() { 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; +} diff --git a/lectures/lec5/p1/task7.js b/lectures/lec5/p1/task7.js index dc049df..90d7095 100644 --- a/lectures/lec5/p1/task7.js +++ b/lectures/lec5/p1/task7.js @@ -1,3 +1,13 @@ sum = function(...args) { 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; } \ No newline at end of file diff --git a/lectures/lec5/p1/task8.js b/lectures/lec5/p1/task8.js index 79fcdad..7c72096 100644 --- a/lectures/lec5/p1/task8.js +++ b/lectures/lec5/p1/task8.js @@ -1,3 +1,12 @@ sum = (...args) => { 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; } \ No newline at end of file