The Wayback Machine - https://web.archive.org/web/20170626175726/https://github.com/lodash/lodash/blob/master/invert.js
Skip to content
Permalink
3c2795b Mar 5, 2017
@jdalton @falsyvalues
26 lines (24 sloc) 615 Bytes
/**
* Creates an object composed of the inverted keys and values of `object`.
* If `object` contains duplicate values, subsequent values overwrite
* property assignments of previous values.
*
* @since 0.7.0
* @category Object
* @param {Object} object The object to invert.
* @returns {Object} Returns the new inverted object.
* @example
*
* const object = { 'a': 1, 'b': 2, 'c': 1 }
*
* invert(object)
* // => { '1': 'c', '2': 'b' }
*/
function invert(object) {
const result = {}
Object.keys(object).forEach((value, key) => {
result[value] = key
})
return result
}
export default invert
You can't perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.