Interface JS5ArrayFunctions

    • Method Detail

      • every

        JSBoolean every​(JS5Function predicate,
                        JS5Object o)
        function every(predicate, o) test whether predicate is true for every element.

        Example

         [1,2,3].every(function(x){return x < 5;} //=>true
         [1,2,3].every(function(x){return x < 2;} //=>false
         [].every(function(x){return false;} //=>true, always true for []
         
        Parameters:
        predicate - A predicate function to test array elements
        o - The optional this value for invocations of predicate.
        Since:
        Standard ECMA-262 5th. Edition
        See Also:
        Array, filter(), forEach(), some()
      • filter

        JS5Array filter​(JS5Function predicate,
                        JS5Object o)
        function filter(predicate, o) return array elements that pass a predicate.

        Example

         [1,2,3].filter(function(x){return x > 1}); // returns [2,3]
         
        Parameters:
        predicate - The function to invoke to determine whether an element of array will be included in the returned array.
        o - An optional value on which predicate is invoked
        Since:
        Standard ECMA-262 5th. Edition
        See Also:
        Array, every(), forEach(), indexOf(), map(), reduce()
      • forEach

        void forEach​(JS5Function f,
                     JS5Object o)
        function forEach(f, o) invoke a function for each array element.

        Example

         var a = [1,2,3];
         a.forEach(function(x,i,a){a[i]++;}); //a is now [2,3,4]
         
        Parameters:
        f - The function to invoke for each element of array
        o - An optional value on which f is invoked
        Since:
        Standard ECMA-262 5th. Edition
        See Also:
        Array
      • indexOf

        JSNumber indexOf​(JS5Object value,
                         JSNumber start)
        function indexOf(value, start) search an array.

        Example

         ['a','b','c'].indexOf('b'); //returns 1
         ['a','b','c'].indexOf('d'); //returns -1
         ['a','b','c'].indexOf('a',1); //returns -1
         
        Parameters:
        value - The value to search array for.
        start - An optional array index at which to begin the search. If omitted, 0 is used.
        Since:
        Standard ECMA-262 5th. Edition
        See Also:
        Array, lastIndexOf()
      • lastIndexOf

        JSNumber lastIndexOf​(JS5Object value,
                             JSNumber start)
        function lastIndexOf(value, start) search backwards through an array.
        Parameters:
        value - The value to search array for.
        start - An optional array index at which to begin the search. If omitted, the search begins at the last element
        Since:
        Standard ECMA-262 5th. Edition
        See Also:
        Array, indexOf()
      • map

        JS5Array map​(JS5Function f,
                     JS5Object o)
        function map(f, o) compute new array elements from old.

        Example

         [1,2,3].map(function(x){return x*x;}); //returns [1,4,9]
         
        Parameters:
        f - The function to invoke for each element of array. Its return becomes the elements of the returned array
        o - An optional value of which f is invoked
        Since:
        Standard ECMA-262 5th. Edition
        See Also:
        Array, every(), filter(), forEach(), reduce()
      • reduce

        JS5Object reduce​(JS5Function f,
                         JS5Object initial)
        function reduce(f, initial) compute a value from the elements of an array.

        Example

         [1,2,3].reduce(function(x,y){return x*y;}); //returns 6 ((1*2(*3))
         
        Parameters:
        f - A function that combines two values and returns a "reduced" value
        initial - An optional initial value to see the array reduction with.
        Since:
        Standard ECMA-262 5th. Edition
        See Also:
        Array, forEach(), map(), reduceRight()
      • reduceRight

        JS5Object reduceRight​(JS5Function f,
                              JS5Object initial)
        function reduceRight(f, initial) reduce an array from right-to-left.

        Example

         [2,10,60].reduceRight(function(x,y){return x/y;}); //returns 3 (60/10)/2
         
        Parameters:
        f - A function that combines two values and returns a "reduced" value
        initial - An optional initial value to see the array reduction with.
        Since:
        Standard ECMA-262 5th. Edition
        See Also:
        Array, reduce()
      • some

        JSBoolean some​(JS5Function predicate,
                       JS5Object o)
        function some(predicate, o) test whether a predicate is true for any element.

        Example

         [1,2,3].some(function(x){return x > 5;} //=>false
         [1,2,3].some(function(x){return x > 2;} //=>true
         [].some(function(x){return true;} //=>false, always false for []
         
        Parameters:
        predicate - A predicate function to test array elements.
        o - The optional this value for the invocations of predicate.
        Since:
        Standard ECMA-262 5th. Edition
        See Also:
        Array