Last active
December 4, 2019 16:52
-
-
Save ahmehri/4c520e694826f627813d4203c45fbd34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { keyBy, mapKeys } = require("lodash"); | |
let result; | |
const current = { | |
firstName: "Ahmed", | |
lastName: "Mehri", | |
age: 30 | |
}; | |
const expected = { | |
Ahmed: { | |
firstName: "Ahmed", | |
lastName: "Mehri", | |
age: 30 | |
} | |
}; | |
// doesn't work either (wrong usage of mapKeys) | |
result = mapKeys(current, "firstName"); // { undefined: 30 } | |
// doesn't work either (correct usage of mapKeys) | |
result = mapKeys(current, (value, key) => value); // { 30: 30, Ahmed: 'Ahmed', Mehri: 'Mehri' } | |
// does not work | |
result = keyBy(current, "firstName"); // { undefined: 30 } | |
// works only on collection | |
const collection = [current]; | |
result = keyBy(collection, "firstName"); // { Ahmed: { firstName: 'Ahmed', lastName: 'Mehri', age: 30 } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment