_assocIndexOf.js 487 B

12345678910111213141516171819202122
  1. var eq = require('./eq');
  2. /**
  3. * Gets the index at which the `key` is found in `array` of key-value pairs.
  4. *
  5. * @private
  6. * @param {Array} array The array to inspect.
  7. * @param {*} key The key to search for.
  8. * @returns {number} Returns the index of the matched value, else `-1`.
  9. */
  10. function assocIndexOf(array, key) {
  11. var length = array.length;
  12. while (length--) {
  13. if (eq(array[length][0], key)) {
  14. return length;
  15. }
  16. }
  17. return -1;
  18. }
  19. module.exports = assocIndexOf;