time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

repl.txt (1623B)


      1 
      2 {{alias}}( arr, [options,] clbk )
      3     Finds elements in an array-like object that satisfy a test condition.
      4 
      5     Parameters
      6     ----------
      7     arr: Array|TypedArray|string
      8         Object from which elements will be tested.
      9 
     10     options: Object (optional)
     11         Options.
     12 
     13     options.k: integer (optional)
     14         Limits the number of returned elements. The sign determines the
     15         direction in which to search. If set to a negative integer, the function
     16         searches from last element to first element. Default: arr.length.
     17 
     18     options.returns: string (optional)
     19         If `values`, values are returned; if `indices`, indices are returned; if
     20         `*`, both indices and values are returned. Default: 'indices'.
     21 
     22     clbk: Function
     23         Function invoked for each array element. If the return value is truthy,
     24         the value is considered to have satisfied the test condition.
     25 
     26     Returns
     27     -------
     28     out: Array
     29         Array of indices, element values, or arrays of index-value pairs.
     30 
     31     Examples
     32     --------
     33     > var data = [ 30, 20, 50, 60, 10 ];
     34     > function condition( val ) { return val > 20; };
     35     > var vals = {{alias}}( data, condition )
     36     [ 0, 2, 3 ]
     37 
     38     // Limit number of results:
     39     > data = [ 30, 20, 50, 60, 10 ];
     40     > var opts = { 'k': 2, 'returns': 'values' };
     41     > vals = {{alias}}( data, opts, condition )
     42     [ 30, 50 ]
     43 
     44     // Return both indices and values as index-value pairs:
     45     > data = [ 30, 20, 50, 60, 10 ];
     46     > opts = { 'k': -2, 'returns': '*' };
     47     > vals = {{alias}}( data, opts, condition )
     48     [ [ 3, 60 ], [ 2, 50 ] ]
     49 
     50     See Also
     51     --------
     52