time-to-botec

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

index.js (1674B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2018 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 'use strict';
     20 
     21 /**
     22 * Return the first index at which a given element can be found.
     23 *
     24 * @module @stdlib/utils/index-of
     25 *
     26 * @example
     27 * var indexOf = require( '@stdlib/utils/index-of' );
     28 *
     29 * var arr = [ 4, 3, 2, 1 ];
     30 * var idx = indexOf( arr, 3 );
     31 * // returns 1
     32 *
     33 * arr = [ 4, 3, 2, 1 ];
     34 * idx = indexOf( arr, 5 );
     35 * // returns -1
     36 *
     37 * // Using a `fromIndex`:
     38 * arr = [ 1, 2, 3, 4, 5, 2, 6 ];
     39 * idx = indexOf( arr, 2, 3 );
     40 * // returns 5
     41 *
     42 * // `fromIndex` which exceeds `array` length:
     43 * arr = [ 1, 2, 3, 4, 2, 5 ];
     44 * idx = indexOf( arr, 2, 10 );
     45 * // returns -1
     46 *
     47 * // Negative `fromIndex`:
     48 * arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];
     49 * idx = indexOf( arr, 2, -4 );
     50 * // returns 5
     51 *
     52 * idx = indexOf( arr, 2, -1 );
     53 * // returns 7
     54 *
     55 * // Negative `fromIndex` exceeding input `array` length:
     56 * arr = [ 1, 2, 3, 4, 5, 2, 6 ];
     57 * idx = indexOf( arr, 2, -10 );
     58 * // returns 1
     59 *
     60 * // Array-like objects:
     61 * var str = 'bebop';
     62 * idx = indexOf( str, 'o' );
     63 * // returns 3
     64 */
     65 
     66 // MODULES //
     67 
     68 var indexOf = require( './index_of.js' );
     69 
     70 
     71 // EXPORTS //
     72 
     73 module.exports = indexOf;