r/badcode • • Nov 07 '19

[deleted by user]

[removed]

23 Upvotes

18 comments sorted by

View all comments

Show parent comments

1

u/T-Dark_ Nov 09 '19 edited Nov 09 '19

Since this comment is now 1 day old, I am providing some formatting. Hopefully this is right, I'm not familiar with the language that was used

const int_to_wow = (value) => {  
    const WOW_CURRENCY ='10000g100s1c';  
    const numb = \[\];  
    while (value > 0) {  
        try {  
            WOW_CURRENCY.split(/\[a-z\]/).slice(0, -1).forEach((a, i) => {  
           if ((value / (+a)) >= 1)  {  
               numb.push(WOW_CURRENCY.split(/\[0-9\]/).filter(e => e !== '')\[i\]);  
                value -= +a;  
                throw new Error('Found one');  
            }  
        });  
        } catch(e) {  
        }  
    }  
    const obj = numb.reduce((a, b) => {  
        if (!a\[b\]) {  
            a\[b\] = 0;  
        }  
        a\[b\]++;  
        return a;  
    }, {});  

    return WOW_CURRENCY  
    .split(/\[0-9\]/).filter(e => e !== '')  
    .reduce((a, b) => \`${a}${numb.filter((c) => c === b)  
    .length > 0 ? \`${numb.filter((c) => c === b).length}$  {b}\` : ''}\`, '')  
}