1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-19 14:16:55 +02:00
CodeWars/6kyu/halloween_trick_or_treat/solution.js
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

27 lines
522 B
JavaScript

function trickOrTreat(children,candies){
if (candies.length != children) {
return "Trick or treat!";
}
let lastCount = -1;
for (let packet of candies) {
let count = 0;
for (let e of packet) {
if (e == "bomb") {
return "Trick or treat!";
} else if (e == "candy") {
count++;
}
}
if (lastCount == -1) {
lastCount = count;
}
if (count < 2 || lastCount != count) {
return "Trick or treat!";
}
}
return "Thank you, strange uncle!";
}