mirror of
https://gitlab.com/mfocko/CodeWars.git
synced 2024-11-09 11:09:07 +01:00
27 lines
522 B
JavaScript
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!";
|
|
}
|