indexOf.js 913 B

123456789101112131415161718192021222324252627282930
  1. import _curry2 from "./internal/_curry2.js";
  2. import _indexOf from "./internal/_indexOf.js";
  3. import _isArray from "./internal/_isArray.js";
  4. /**
  5. * Returns the position of the first occurrence of an item in an array, or -1
  6. * if the item is not included in the array. [`R.equals`](#equals) is used to
  7. * determine equality.
  8. *
  9. * @func
  10. * @memberOf R
  11. * @since v0.1.0
  12. * @category List
  13. * @sig a -> [a] -> Number
  14. * @param {*} target The item to find.
  15. * @param {Array} xs The array to search in.
  16. * @return {Number} the index of the target, or -1 if the target is not found.
  17. * @see R.lastIndexOf, R.findIndex
  18. * @example
  19. *
  20. * R.indexOf(3, [1,2,3,4]); //=> 2
  21. * R.indexOf(10, [1,2,3,4]); //=> -1
  22. */
  23. var indexOf =
  24. /*#__PURE__*/
  25. _curry2(function indexOf(target, xs) {
  26. return typeof xs.indexOf === 'function' && !_isArray(xs) ? xs.indexOf(target) : _indexOf(xs, target, 0);
  27. });
  28. export default indexOf;