> Functions
Returns the sum of all the numeric elements of the array array.
In JavaScript there is no native sum: you write a.reduce((s, x) => s + x, 0). Two traps. Without an initial value, reduce raises a TypeError on an empty array: keep the 0. And + concatenates as soon as an element is a string — ["a", "b"].reduce((s, x) => s + x, 0) is the string "0ab", not a number.
In Python, sum() raises a TypeError as soon as an element is not a number, where sum in LeekScript converts every element (a non-numeric string becomes its length there). Another difference, the type of the result follows that of the elements: sum([1, 2]) returns the integer 3, when sum in LeekScript always returns a real. sum([]) is 0, and a second argument gives the starting value — sum([1, 2], 10) is 13.
Impossible de charger les données du jeu.
Vérifiez votre connexion et réessayez.