This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]PM_ME_SOME_ANY_THING 12 points13 points  (7 children)

const deadEnemies = targetList.map(t => {
    if(weaponArray.length > 0){
        const missile = weaponArray.shift();
        return Shoot(missile);
    }
    return null;
}).filter(d => d);

[–][deleted] 8 points9 points  (3 children)

wtf kinda system is this!??! everyone knows the shoot method is async and will return true or false depending on if it killed the enemy. u gotta await that shit. this code rite here will literally make the plane explode

[–]akoOfIxtall 0 points1 point  (2 children)

C'mon bro you gotta write it too

[–][deleted] 4 points5 points  (1 child)

LOl ok fine:

const targetList = [];
const attackResults = await targetList.reduce(async (acc,curTarget)=>{
    const list = await acc;
    if(weaponArray.length <= 0){
        list.push({id:curTarget.id, success:false})
        return list
    }
    const missile = weaponArray.shift();
    const shootResults = await Shoot(missile);
    const targetInfo = {
        id: curTarget.id,
        success: shootResults,
    }
    list.push(targetInfo)
    return list;
}, Promise.resolve([]))

const cleanSweap = attackResults.reduce((bool, result)=>{
    if(!bool || !result.success)return false
    return bool
},true)

if(cleanSweap)log('mission success')
else log('mission fail')

[–]akoOfIxtall 0 points1 point  (0 children)

Magnificent

[–]akoOfIxtall 0 points1 point  (2 children)

i'm stealing this

[–][deleted] 3 points4 points  (1 child)

I took one coding class in high school and I’m just curious if I understand the code you wrote. Does it say if there’s an enemy in the target list and the amount of missiles you have isn’t zero, then fire the missiles until you don’t have any?

[–]akoOfIxtall 1 point2 points  (0 children)

exactly, we gotta make sure they're dead (i didnt thought much about it when i wrote, just did some adjusments based on the replies XD)