#javascript reduce is messed up

8 messages · Page 1 of 1 (latest)

minor solstice
#

for some reason it makes an outofbounds exception???

lunar runeBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

minor solstice
#
let v = inventory.findAll().reduce((a,b) => a+b==null?0:b.nbt==null?1:b.nbt.value,0)

with inventory being a ModifyRecipeCraftingGrid type

#
var v = 0
for (var n of inventory.findAll()) {
    v += n==null?0:n.nbt==null?1:n.nbt.value
}

i also made this for loop version that works fine but looks less cool

#

and here's the whole error message (tldr: out of bounds 1 for array size 1)

obsidian sonnetBOT
#

Paste version of message.txt from @minor solstice

minor solstice
#

ok i realized this is way easier without reducing

#
let a = inventory.find(Item.of('minestuck:boondollars').ignoreNBT()).nbt
let b = inventory.find(Item.of('minestuck:boondollars').ignoreNBT(),1).nbt
return itemstack.withNBT({value:(a?a.value:1)+(b?b.value:1)})