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