mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 20:07:49 +00:00
Simplify mapKey and mapValue.
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
import baseAssignValue from './.internal/baseAssignValue.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The opposite of `mapValue` this method creates an object with the
|
* The opposite of `mapValue` this method creates an object with the
|
||||||
* same values as `object` and keys generated by running each own enumerable
|
* same values as `object` and keys generated by running each own enumerable
|
||||||
@@ -21,8 +19,9 @@ import baseAssignValue from './.internal/baseAssignValue.js'
|
|||||||
*/
|
*/
|
||||||
function mapKey(object, iteratee) {
|
function mapKey(object, iteratee) {
|
||||||
const result = {}
|
const result = {}
|
||||||
Object.keys(object).forEach((value, key, object) => {
|
Object.keys(Object(object)).forEach((key) => {
|
||||||
baseAssignValue(result, iteratee(value, key, object), value)
|
const value = object[key]
|
||||||
|
result[iteratee(value, key, object)] = value
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import baseAssignValue from './.internal/baseAssignValue.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an object with the same keys as `object` and values generated
|
* Creates an object with the same keys as `object` and values generated
|
||||||
* by running each own enumerable string keyed property of `object` thru
|
* by running each own enumerable string keyed property of `object` thru
|
||||||
@@ -24,8 +22,8 @@ import baseAssignValue from './.internal/baseAssignValue.js'
|
|||||||
*/
|
*/
|
||||||
function mapValue(object, iteratee) {
|
function mapValue(object, iteratee) {
|
||||||
const result = {}
|
const result = {}
|
||||||
Object.keys(object).forEach((value, key, object) => {
|
Object.keys(Object(object)).forEach((key) => {
|
||||||
baseAssignValue(result, key, iteratee(value, key, object))
|
result[key] = iteratee(object[value], key, object)
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user