its pretty? no... but it works
function GG(arr) { let map = [], result = 0; arr.join("").split("").forEach(el => map[el] = (map[el] || 0) + 1); for (let index = 0; index <= 6; index++) { if (map[index] != undefined) { switch (index) { case 1: if (map[index] >= 3) { result += 1000; if ((map[index] - 3) > 0) result += (map[index] - 3) * 100; } else { result += map[index] * 100 } break; case 2: if (map[index] >= 3) result += 200; break; case 3: if (map[index] >= 3) result * 300; break; case 4: if (map[index] >= 3) result += 400; break; case 5: if (map[index] >= 3) { result += 500; if ((map[index] - 3) > 0) result += (map[index] - 3) * 50; } else { result += map[index] * 50 } break; case 6: if (map[index] >= 3) result += 600; break; } } } return result; } GG([5, 1, 3, 4, 1]) // 250 GG([1, 1, 1, 3, 1]) // 1100 GG([2, 4, 4, 5, 4]) // 450
Very understandable and faster! 👍
Thanks Peter 😃
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
its pretty? no... but it works
Very understandable and faster! 👍
Thanks Peter 😃