mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 18:07:49 +00:00
Consolidate invert modules.
This commit is contained in:
14
invert.js
14
invert.js
@@ -1,6 +1,4 @@
|
||||
import constant from './constant.js';
|
||||
import createInverter from './.internal/createInverter.js';
|
||||
import identity from './identity.js';
|
||||
import baseForOwn from './baseForOwn.js';
|
||||
|
||||
/**
|
||||
* Creates an object composed of the inverted keys and values of `object`.
|
||||
@@ -18,8 +16,12 @@ import identity from './identity.js';
|
||||
* invert(object);
|
||||
* // => { '1': 'c', '2': 'b' }
|
||||
*/
|
||||
const invert = createInverter((result, value, key) => {
|
||||
result[value] = key;
|
||||
});
|
||||
function invert(object) {
|
||||
const result = {};
|
||||
baseForOwn(object, (value, key) => {
|
||||
result[value] = key;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export default invert;
|
||||
|
||||
Reference in New Issue
Block a user