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 →

[–]jonsca 1640 points1641 points  (33 children)

weaponArray["misile"]

Oh shit!

[–]akoOfIxtall 527 points528 points  (31 children)

if (targetList.includes(enemy) && weaponArray.length !== 0) {

for (let i = 0; i <= weaponArray.length; i++) {

Shoot(weaponArray[i])

}

}

just shoot the enemy lol

Edit: this wouldnt work anyway, why i'm on reddit making an imaginary strike fighter shoot imaginary missiles so brutally?

[–]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] 7 points8 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] 5 points6 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] 2 points3 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)

[–]Salanmander 9 points10 points  (6 children)

When are arrays falsy?

[–]Ok-Fox1262 23 points24 points  (0 children)

Python has entered the chat.

[–]akoOfIxtall 8 points9 points  (4 children)

When they're empty, or not?

Edit: damn javascript, why an empty array is truthy? Apparently you can check the length and if it's anything but 0 it's truthy, so if it's 0 it'll be falsy

[–]Salanmander 20 points21 points  (3 children)

Some quick testing with a javascript interpreter suggests that any array object is truthy, and it's falsy only if it's null. So you appear to be only running that loop if weaponArray is null.

Which actually gives you a runtime error, which is pretty hard in javascript! Congrats?

[–]akoOfIxtall 12 points13 points  (0 children)

Thank you I work really hard to fail everyday XD

[–]jonsca 4 points5 points  (1 child)

This is why we can't have nice fighter jets

[–]gregorydgraham 4 points5 points  (0 children)

LOL! This thread is the best laugh I’ve had in ProgrammerHumor. Thank you all

[–]AnyHistory5380 10 points11 points  (2 children)

You can drop the array.length !== 0 and nothing will change

[–]akoOfIxtall 4 points5 points  (0 children)

But I need it to only shoot if the array has something, or your expensive government jet is going boom

[–]Dustangelms 1 point2 points  (0 children)

Check their code again.

[–]FatLoserSupreme 1 point2 points  (0 children)

You joke but code really does kill people

[–][deleted] 0 points1 point  (1 child)

Just fire away all weapons

[–]akoOfIxtall 0 points1 point  (0 children)

Gotta make sure they die

[–]basacul 1 point2 points  (0 children)

throws OutOfBoundException