time-to-botec

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

README.md (2901B)


      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 # reverseArguments
     22 
     23 > Create a function that invokes a provided function with arguments in reverse order.
     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 reverseArguments = require( '@stdlib/utils/reverse-arguments' );
     41 ```
     42 
     43 #### reverseArguments( fcn\[, thisArg] )
     44 
     45 Returns a `function` that invokes a provided function with `arguments` in reverse order.
     46 
     47 ```javascript
     48 function foo( a, b ) {
     49     return [ a, b ];
     50 }
     51 
     52 var bar = reverseArguments( foo );
     53 
     54 var out = bar( 1, 2 );
     55 // returns [ 2, 1 ]
     56 ```
     57 
     58 To set the `this` context when invoking the provided function, provide a `thisArg`.
     59 
     60 <!-- eslint-disable no-restricted-syntax -->
     61 
     62 ```javascript
     63 function Foo() {
     64     this.x = 1;
     65     this.y = 2;
     66 }
     67 
     68 Foo.prototype.scale = function scale( a, b ) {
     69     return [ this.x*a, this.y*b ];
     70 };
     71 
     72 var ctx = {
     73     'x': 10,
     74     'y': 20
     75 };
     76 
     77 var foo = new Foo();
     78 
     79 var bar = reverseArguments( foo.scale, ctx );
     80 
     81 var out = bar( 1, 2 );
     82 // returns [ 20, 20 ]
     83 ```
     84 
     85 </section>
     86 
     87 <!-- /.usage -->
     88 
     89 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     90 
     91 <section class="notes">
     92 
     93 </section>
     94 
     95 <!-- /.notes -->
     96 
     97 <!-- Package usage examples. -->
     98 
     99 <section class="examples">
    100 
    101 ## Examples
    102 
    103 <!-- eslint no-undef: "error" -->
    104 
    105 ```javascript
    106 var reverseArguments = require( '@stdlib/utils/reverse-arguments' );
    107 
    108 function foo( a, b, c ) {
    109     return [ a, b, c ];
    110 }
    111 
    112 var bar = reverseArguments( foo );
    113 
    114 var out = foo( 1, 2, 3 );
    115 // returns [ 1, 2, 3 ]
    116 
    117 out = bar( 1, 2, 3 );
    118 // returns [ 3, 2, 1 ]
    119 ```
    120 
    121 </section>
    122 
    123 <!-- /.examples -->
    124 
    125 <!-- 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. -->
    126 
    127 <section class="references">
    128 
    129 </section>
    130 
    131 <!-- /.references -->
    132 
    133 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    134 
    135 <section class="links">
    136 
    137 </section>
    138 
    139 <!-- /.links -->