time-to-botec

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

README.md (2631B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # Array-Like Function
     22 
     23 > Return a function which tests if every element in an array-like object passes a test condition.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var arraylikefcn = require( '@stdlib/assert/tools/array-like-function' );
     31 ```
     32 
     33 <a name="arraylikefcn"></a>
     34 
     35 #### arraylikefcn( predicate )
     36 
     37 Returns a function which tests if every element in an [array-like object][array-like] passes a test condition. Given an input [array-like object][array-like], the function returns `true` if all elements pass the test and `false` otherwise.
     38 
     39 ```javascript
     40 var isOdd = require( '@stdlib/assert/is-odd' );
     41 
     42 var arr1 = [ 1, 3, 5, 7 ];
     43 var arr2 = [ 3, 5, 8 ];
     44 
     45 var f = arraylikefcn( isOdd );
     46 
     47 var bool = f( arr1 );
     48 // returns true
     49 
     50 bool = f( arr2 );
     51 // returns false
     52 ```
     53 
     54 </section>
     55 
     56 <!-- /.usage -->
     57 
     58 <section class="notes">
     59 
     60 ## Notes
     61 
     62 -   The returned function will return `false` if **not** provided an [array-like object][array-like].
     63 -   The returned function will return `false` if provided an empty [array-like object][array-like].
     64 -   A `predicate` function should accept a single argument: an element from an [array-like object][array-like]. If the element satisfies a test condition, the `predicate` function should return `true`; otherwise, the `predicate` function should return `false`.
     65 
     66 </section>
     67 
     68 <!-- /.notes -->
     69 
     70 <section class="examples">
     71 
     72 ## Examples
     73 
     74 <!-- eslint no-undef: "error" -->
     75 
     76 ```javascript
     77 var isEven = require( '@stdlib/assert/is-even' );
     78 var arraylikefcn = require( '@stdlib/assert/tools/array-like-function' );
     79 
     80 var arr1;
     81 var arr2;
     82 var bool;
     83 var f;
     84 var i;
     85 
     86 arr1 = new Array( 25 );
     87 for ( i = 0; i < arr1.length; i++ ) {
     88     arr1[ i ] = i;
     89 }
     90 
     91 arr2 = new Array( 25 );
     92 for ( i = 0; i < arr2.length; i++ ) {
     93     arr2[ i ] = 2 * i;
     94 }
     95 
     96 f = arraylikefcn( isEven );
     97 
     98 bool = f( arr1 );
     99 // returns false
    100 
    101 bool = f( arr2 );
    102 // returns true
    103 ```
    104 
    105 </section>
    106 
    107 <!-- /.examples -->
    108 
    109 <section class="links">
    110 
    111 [array-like]: http://www.2ality.com/2013/05/quirk-array-like-objects.html
    112 
    113 </section>
    114 
    115 <!-- /.links -->