invert.js 344 B

12345678910111213141516
  1. define(['./keys'], function (keys) {
  2. // Invert the keys and values of an object. The values must be serializable.
  3. 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. }
  11. return invert;
  12. });