object.js 537 B

1234567891011121314151617
  1. import getLength from './_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. export default 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. }