underscore-es
Version:
javaScript's functional programming helper library for ES6 and beyond.
19 lines (17 loc) • 537 B
JavaScript
// `_object` : an array's function
// --------------------------------
import {getLength} from './_internal';
// Converts lists into objects. Pass either a single array of `[key, value]`
// pairs, or two parallel arrays of the same length -- one of keys, and one of
// the corresponding values.
export default function (list, values) {
let result = {};
for (let i = 0, length = getLength(list); i < length; i++) {
if (values) {
result[list[i]] = values[i];
} else {
result[list[i][0]] = list[i][1];
}
}
return result;
}