summary refs log tree commit diff stats
path: root/javascript/raindrops/raindrops.js
blob: 4a39ec9d8201c751c49976fe0a8d600abcaa666c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 
'use strict';

export const convert = (number) => {
    const factorToSound = new Map([
        [3, 'Pling'],
        [5, 'Plang'],
        [7, 'Plong']
    ]);

    let drops = "";
    for (const [factor, sound] of factorToSound)
        if (number % factor === 0)
             drops += sound;

    if (drops === "")
        drops += number;

    return drops;
};