Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Clarify any, notall, head, remove 'regexp supported' from index(), grammar, fix sort definition

The following operators are valid for arrays.  NoteNote: in addition to these operators, there is a membership infix operator that works on arrays and maps, and there are also Set Operators, which are extremely useful when comparing & inspecting arrays. 

...

The all() operator takes a function as it's its sole argument. All() returns a true value if the function returns true for every item in the target array or if the target array is empty. 

...

The any() operator takes a function as it's its sole argument. Any() returns a true value if the function returns true for any at least one item in the target array.

...

The head() operator returns the first member of an array as a single value, or null if the array is empty.

Code Block
languagejavascript
themeConfluence
c = [3, 4, 5];
c.head() // c = 3

...

The types of matched values must be num, str, regexp, or bool. The operator does not match complex other types of values.

Returns -1 if no such item could be found.

...

The none() operator takes a function as it's its sole argument. None() returns a true value if the function returns false for every item in the target array or if the target array is empty. None() is the logical negation of any()

...

The notall() operator takes a function as it's sole argument. Notall() returns a true value if the function returns false for any at least one item in the target array. This is the logical inverse of all().

...

When using reduce() with arrays that contain values whose type differs from the return type of the function, the first argument to the function should have the same type as the returned value, and you must supply a default value that has the same type as the return value of the function.  For example:

...

  • If the argument is empty, the array will be sorted in ascending order using a string comparison.
  • If the argument is the string "reverse", the array will be sorted in descending order using a string comparison.
  • If the argument is the string "numeric", the array will be sorted in ascending order using a number comparison.
  • If the argument is the string "ciremun" ("numeric" backwards), the array will be sorted in descending order using a number comparison.
  • If the argument is a function, the function will be used to perform pair-wise comparisons of the members of the array for purposes of doing the sort. The function must take two arguments and return -1, 0, or 1 depending on whether the first argument is less than, equal to, or less greater than the second. The <=> and cmp comparison operators are useful with sort().

...

The tail() operator returns a new array that is the original array with the first element removed, or an empty array if the original array is empty. For example:

Code Block
languagejavascript
themeConfluence
a = [3, 4, 5];
c = a.tail(); // c = [4, 5]

...