1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-12 20:40:28 +01:00
CodeWars/6kyu/halloween_trick_or_treat/solution.js

28 lines
522 B
JavaScript
Raw Normal View History

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!";
}