time-to-botec

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

README.md (2564B)


      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 Function
     22 
     23 > Return a function which tests if every element in an array passes a test condition.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var arrayfcn = require( '@stdlib/assert/tools/array-function' );
     31 ```
     32 
     33 <a name="arrayfcn"></a>
     34 
     35 #### arrayfcn( predicate )
     36 
     37 Returns a function which tests if every element in an [`array`][mdn-array] passes a test condition. Given an input [`array`][mdn-array], 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 = arrayfcn( 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`][mdn-array].
     63 -   The returned function will return `false` if provided an empty [`array`][mdn-array].
     64 -   A `predicate` function should accept a single argument: an [`array`][mdn-array] element. If the [`array`][mdn-array] 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 arrayfcn = require( '@stdlib/assert/tools/array-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 = arrayfcn( 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 [mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
    112 
    113 </section>
    114 
    115 <!-- /.links -->