time-to-botec

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

README.md (4826B)


      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 # noneByRight
     22 
     23 > Test whether all elements in a collection fail a test implemented by a predicate function, iterating from right to left.
     24 
     25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
     26 
     27 <section class="intro">
     28 
     29 </section>
     30 
     31 <!-- /.intro -->
     32 
     33 <!-- Package usage documentation. -->
     34 
     35 <section class="usage">
     36 
     37 ## Usage
     38 
     39 ```javascript
     40 var noneByRight = require( '@stdlib/utils/none-by-right' );
     41 ```
     42 
     43 #### noneByRight( collection, predicate\[, thisArg ] )
     44 
     45 Tests whether all elements in a `collection` fail a test implemented by a `predicate` function, iterating from right to left.
     46 
     47 ```javascript
     48 function isPositive( value ) {
     49     return ( value > 0 );
     50 }
     51 
     52 var arr = [ -1, -2, -3, -4 ];
     53 
     54 var bool = noneByRight( arr, isPositive );
     55 // returns true
     56 ```
     57 
     58 If a `predicate` function returns a truthy value, the function **immediately** returns `false`.
     59 
     60 ```javascript
     61 function isPositive( value ) {
     62     return ( value > 0 );
     63 }
     64 
     65 var arr = [ -1, 2, -3, -4 ];
     66 
     67 var bool = noneByRight( arr, isPositive );
     68 // returns false
     69 ```
     70 
     71 The invoked `function` is provided three arguments:
     72 
     73 -   `value`: collection element
     74 -   `index`: collection index
     75 -   `collection`: input collection
     76 
     77 To set the function execution context, provide a `thisArg`.
     78 
     79 ```javascript
     80 function sum( value ) {
     81     if ( value < 0 ) {
     82         return true;
     83     }
     84     this.sum += value;
     85     this.count += 1;
     86     return false;
     87 }
     88 
     89 var arr = [ 1, 2, 3, 4 ];
     90 
     91 var context = {
     92     'sum': 0,
     93     'count': 0
     94 };
     95 
     96 var bool = noneByRight( arr, sum, context );
     97 // returns true
     98 
     99 var mean = context.sum / context.count;
    100 // returns 2.5
    101 ```
    102 
    103 </section>
    104 
    105 <!-- /.usage -->
    106 
    107 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    108 
    109 <section class="notes">
    110 
    111 ## Notes
    112 
    113 -   A `collection` may be either an [`Array`][mdn-array], [`Typed Array`][mdn-typed-array], or an array-like [`Object`][mdn-object] (excluding `strings` and `functions`).
    114 
    115 -   If provided an empty collection, the function returns `true`.
    116 
    117     ```javascript
    118     function truthy() {
    119         return true;
    120     }
    121     var bool = noneByRight( [], truthy );
    122     // returns true
    123     ```
    124 
    125 -   The function does **not** skip `undefined` elements.
    126 
    127     <!-- eslint-disable no-sparse-arrays, stdlib/doctest-marker -->
    128 
    129     ```javascript
    130     function log( value, index ) {
    131         console.log( '%s: %s', index, value );
    132         return false;
    133     }
    134 
    135     var arr = [ 1, , , 4 ];
    136 
    137     var bool = noneByRight( arr, log );
    138     /* =>
    139         3: 4
    140         2: undefined
    141         1: undefined
    142         0: 1
    143     */
    144     ```
    145 
    146 -   The function provides limited support for dynamic collections (i.e., collections whose `length` changes during execution). Note, however, that index incrementation is **not** guaranteed to be monotonically **decreasing**.
    147 
    148 </section>
    149 
    150 <!-- /.notes -->
    151 
    152 <!-- Package usage examples. -->
    153 
    154 <section class="examples">
    155 
    156 ## Examples
    157 
    158 <!-- eslint no-undef: "error" -->
    159 
    160 ```javascript
    161 var randu = require( '@stdlib/random/base/randu' );
    162 var noneByRight = require( '@stdlib/utils/none-by-right' );
    163 
    164 function isPositive( value ) {
    165     return ( value > 0 );
    166 }
    167 
    168 var bool;
    169 var arr;
    170 var i;
    171 
    172 arr = new Array( 100 );
    173 for ( i = 0; i < arr.length; i++ ) {
    174     arr[ i ] = -randu();
    175 }
    176 
    177 bool = noneByRight( arr, isPositive );
    178 // returns true
    179 ```
    180 
    181 </section>
    182 
    183 <!-- /.examples -->
    184 
    185 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    186 
    187 <section class="references">
    188 
    189 </section>
    190 
    191 <!-- /.references -->
    192 
    193 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    194 
    195 <section class="links">
    196 
    197 [mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
    198 
    199 [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
    200 
    201 [mdn-object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
    202 
    203 </section>
    204 
    205 <!-- /.links -->