From 9210fd98ac9485ab919b6f691e6f70af13343330 Mon Sep 17 00:00:00 2001 From: Dwarkanath Prabhu Date: Fri, 12 Jun 2020 03:13:43 -0500 Subject: [PATCH] Update solution.js Using reduce rather than a loop --- exercises/baby_steps/solution/solution.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/exercises/baby_steps/solution/solution.js b/exercises/baby_steps/solution/solution.js index 2c5b8396..2cb48bc8 100644 --- a/exercises/baby_steps/solution/solution.js +++ b/exercises/baby_steps/solution/solution.js @@ -1,9 +1,7 @@ 'use strict' -let result = 0 - -for (let i = 2; i < process.argv.length; i++) { - result += Number(process.argv[i]) -} - -console.log(result) +console.log( + process.argv.slice(2).reduce( + (x, y) => x + Number(y), 0 + ) +);