-
Notifications
You must be signed in to change notification settings - Fork 0
/
findKeyByValue.js
28 lines (24 loc) · 943 Bytes
/
findKeyByValue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// FUNCTION IMPLEMENTATION
const assertEqual = function(actual, expected) {
if (actual === expected) {
console.log(`✅✅✅Assertion Passed: ${actual} === ${expected}`);
} else {
console.log(`🛑🛑🛑Assertion Failed: ${actual} !== ${expected}`);
}
};
const findKeyByValue = function (bestTVShowsByGenre, showName) {
let dramaKey = Object.keys(bestTVShowsByGenre).find(
(key) => bestTVShowsByGenre[key] === showName
);
return dramaKey;
};
module.exports = findKeyByValue;
const bestTVShowsByGenre = {
sci_fi: "The Expanse",
comedy: "Brooklyn Nine-Nine",
drama: "The Wire",
};
console.log(findKeyByValue(bestTVShowsByGenre, "The Wire"));
console.log(findKeyByValue(bestTVShowsByGenre, "That '70s Show"));
assertEqual(findKeyByValue(bestTVShowsByGenre, "The Wire"), "drama");
assertEqual(findKeyByValue(bestTVShowsByGenre, "That '70s Show"), undefined);