object.js 552 B

123456789101112131415161718
  1. var _getLength = require('./_getLength.js');
  2. // Converts lists into objects. Pass either a single array of `[key, value]`
  3. // pairs, or two parallel arrays of the same length -- one of keys, and one of
  4. // the corresponding values. Passing by pairs is the reverse of `_.pairs`.
  5. function object(list, values) {
  6. var result = {};
  7. for (var i = 0, length = _getLength(list); i < length; i++) {
  8. if (values) {
  9. result[list[i]] = values[i];
  10. } else {
  11. result[list[i][0]] = list[i][1];
  12. }
  13. }
  14. return result;
  15. }
  16. module.exports = object;