3.1.2 • Published 5 years ago

find-index-x v3.1.2

Weekly downloads
495
License
MIT
Repository
github
Last release
5 years ago

find-index-x

This method returns the index of the first element in the array that satisfies the provided testing function.

module.exportsnumber

Like findIndex, this method returns an index in the array, if an element in the array satisfies the provided testing function. Otherwise -1 is returned.

Kind: Exported member
Returns: number - Returns index of positively tested element, otherwise -1.
Throws:

  • TypeError If array is null or undefined-
  • TypeError If callback is not a function.
ParamTypeDescription
arrayArrayThe array to search.
callbackfunctionFunction to execute on each value in the array, taking three arguments: element, index and array.
thisArg*Object to use as this when executing callback.

Example

import findIndex from 'find-index-x';

function isPrime(element, index, array) {
  let start = 2;
  while (start <= Math.sqrt(element)) {
    if (element % start < 1) {
      return false;
    }

    start += 1;
  }

  return element > 1;
}

console.log(findIndex([4, 6, 8, 12, 14], isPrime)); // -1, not found
console.log(findIndex([4, 6, 7, 12, 13], isPrime)); // 2
3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.17

5 years ago

3.0.16

5 years ago

3.0.15

5 years ago

3.0.14

5 years ago

3.0.13

5 years ago

3.0.12

5 years ago

3.0.11

5 years ago

3.0.10

5 years ago

3.0.9

5 years ago

3.0.8

5 years ago

3.0.7

5 years ago

3.0.6

5 years ago

3.0.5

5 years ago

3.0.4

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.5.0

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago