So my code runs it doesn’t show any errors but when he calls the names he doesn’t call the right names and it runs out of time:
// There are four pairs of twins, they should pray by pairs.
// You need to find twins and call them.
// Twins have the same names, only the last letter is different.
// This function checks if the pair of units are twins.
function areTwins(unit1, unit2) {
var name1 = unit1.id;
var name2 = unit2.id;
if (name1.length !== name2.length) {
return false;
}
for (var i = 0; i < name1.length - 1; i++) {
if (name1[i] !== name2[i]) {
return false;
}
}
return true;
}
// Iterate over all pairs of paladins and
// say() their name by pairs if they are twins.
var twins = hero.findFriends();
for(var i = 0; i < twins.length; i++){
var twin1 = twins[i];
for (var j = 0; j< twins.length; j++){
if (i == j){
continue;
}
var twin2 = twins[j];
hero.say(twin1.id + " " + twin2.id);
}
}
// For example: hero.say("NameTwin1 NameTwin2")
// When twins are in their spots, lure the ogre.
// Don't be afraid of beams - they are dangerous only for ogres.
var enemies = hero.findEnemies();
var enemy = hero.findNearest(enemies);
var dist = hero.findDistanceTo(enemy);
var returnX = 14;
var returnY = 37;
var returnPoint = (returnX, returnY);
while(true){
if (dist < 10) {
hero.move(returnPoint);
}
else {
hero.move(enemy.pos);
}
}