invert.js 311 B

1234567891011
  1. import keys from './keys.js';
  2. // Invert the keys and values of an object. The values must be serializable.
  3. export default function invert(obj) {
  4. var result = {};
  5. var _keys = keys(obj);
  6. for (var i = 0, length = _keys.length; i < length; i++) {
  7. result[obj[_keys[i]]] = _keys[i];
  8. }
  9. return result;
  10. }