Help uneasy truce JS[SOLVED]

This is my code @milton.jinich or @Falcons118 please help

// Summon one soldier for every ogre to the south of you!
// Don't count the ogres to the north!

// Accept an array of units as the parameter.
// Return only the units to the south of the hero.
function findSouthernUnits(units) {
    var southernUnits = [];
    for(var i=0; i < units.length; i++) {
        var unit = units[i];
        if(unit.pos.y < hero.pos.y) {
            // Add the unit to the array with: push()
            southernUnits.push(unit);
        }
    }
    return southernUnits;
}

while(true) {
    var friends = hero.findFriends();
    var enemies = hero.findEnemies();
    // Use findSouthernUnits to get enemies to the south.
    var numEnemies = findSouthernUnits(enemies);
    var numFriends = findSouthernUnits(friends);
    var nf = numFriends.length;
    var ne = numEnemies.length;
    // If there are more ogres south of you than friends.
    if (ne > nf) {
        // Then summon another "soldier".
        hero.summon("soldier");
    }
}

replace this

with this

    enemies = findSouthernUnits(enemies);
    // If there are more ogres south of you than friends.
    if (enemies.length > friends.length) {
        // Then summon another "soldier".
        hero.summon("soldier");
    }
1 Like

@Dragonlouis if what @milton.jinich said worked mark it as solved

Great this problem is solved. My job is done and have a good day or night.

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.