@mattseligman/lotide
Version:
Lotide is a mini clone of the Lodash Library to practice crating a personal npm package. It's like lodash, but without all that extra stuff. Just the things you need to start your project.
24 lines (16 loc) • 490 B
JavaScript
const findKeyByValue = function(object, value) {
for (let key in object) {
if (object[key] === value) {
return key;
}
}
};
module.exports = findKeyByValue;
// Tests to build
// const bestTVShowsByGenre = {
// sci_fi: "The Expanse",
// comedy: "Brooklyn Nine-Nine",
// drama: "The Wire"
// };
// assertEqual(findKeyByValue(bestTVShowsByGenre, "The Wire"), "drama");
// assertEqual(findKeyByValue(bestTVShowsByGenre, "That '70s Show"), undefined);