You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionTS.array_reduce(list, callback, ...)
localfirst=1locallast=#listlocalaccumulator-- support `nil` initialValuesifselect("#", ...) ==0theniflast==0thenerror("Reduce of empty array with no initial value at Array.reduce", 2)
endaccumulator=list[first]
first=first+1elseaccumulator=...endfori=first, lastdoaccumulator=callback(accumulator, list[i], i-1, list)
endreturnaccumulatorendfunctionTS.array_reduceRight(list, callback, ...)
localfirst=#listlocallast=1localaccumulator-- support `nil` initialValuesifselect("#", ...) ==0theniffirst==0thenerror("Reduce of empty array with no initial value at Array.reduceRight", 2)
endaccumulator=list[first]
first=first-1elseaccumulator=...endfori=first, last, -1doaccumulator=callback(accumulator, list[i], i-1, list)
endreturnaccumulatorend
TypescriptToLua Playground
TS Playground
This is the more correct code roblox-ts uses: