From 46d81156b7bad4bef2f4443df6e9df4f03303c56 Mon Sep 17 00:00:00 2001 From: Andinus Date: Sun, 5 Sep 2021 16:38:00 +0530 Subject: JS: Raindrops: Move rules to a const --- javascript/raindrops/raindrops.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'javascript') diff --git a/javascript/raindrops/raindrops.js b/javascript/raindrops/raindrops.js index 54696d3..c7614d5 100644 --- a/javascript/raindrops/raindrops.js +++ b/javascript/raindrops/raindrops.js @@ -1,17 +1,19 @@ 'use strict'; export const convert = (number) => { - let drops = ""; - - [ + const rules = [ {factor: 3, result: 'Pling'}, {factor: 5, result: 'Plang'}, {factor: 7, result: 'Plong'} - ].forEach(drop => { - if (number % drop.factor === 0) - drops += drop.result; - }); + ]; + + let drops = ""; + rules.forEach(drop => { + if (number % drop.factor === 0) + drops += drop.result; + }); - if (drops === "") drops += number; + if (drops === "") + drops += number; return drops; }; -- cgit 1.4.1-2-gfad0