diff options
author | Andinus <andinus@nand.sh> | 2021-09-05 16:38:00 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2021-09-05 16:38:00 +0530 |
commit | 46d81156b7bad4bef2f4443df6e9df4f03303c56 (patch) | |
tree | 0c5a96248f687426bff738f45a21b296fd1766ff | |
parent | 52f2e1a8f60c3c1ef1569be89859e1a555fb740d (diff) | |
download | exercism-46d81156b7bad4bef2f4443df6e9df4f03303c56.tar.gz |
JS: Raindrops: Move rules to a const
-rw-r--r-- | javascript/raindrops/raindrops.js | 18 |
1 files changed, 10 insertions, 8 deletions
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; }; |