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