From 0f89b1b798a9bf1fe1c55f36b49d9a0b2c003400 Mon Sep 17 00:00:00 2001 From: Vitali Timolyanov Date: Thu, 29 Nov 2018 01:56:20 +0200 Subject: [PATCH] Add closure task #1 --- .../homework_5/task_1_closure.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 homeworks/vitali.timolyanov_XX-NF-XX/homework_5/task_1_closure.js diff --git a/homeworks/vitali.timolyanov_XX-NF-XX/homework_5/task_1_closure.js b/homeworks/vitali.timolyanov_XX-NF-XX/homework_5/task_1_closure.js new file mode 100644 index 000000000..c2f87a648 --- /dev/null +++ b/homeworks/vitali.timolyanov_XX-NF-XX/homework_5/task_1_closure.js @@ -0,0 +1,16 @@ +function initSummarizer(defaultValue) { + let summ = defaultValue; + return (num) => { + summ += num; + return summ; + }; +} + +const summarizer = initSummarizer(0); +const testArr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; +const sumArr = testArr.map(summarizer); + +console.log('Test array: '); +console.log(testArr); +console.log('Sum array: '); +console.log(sumArr);