UNPKG

@allenfuture/lotide

Version:
28 lines (25 loc) 702 B
const findKey = function(obj, callbk) { for (let key in obj) { if (callbk(obj[key])) { return key; } } return undefined; }; // test cases: // const assertEqual = function(actual, expected) { // if (actual === expected) { // console.log(`✅✅✅Assertion Passed: ${actual} === ${expected}`); // } else { // console.log(`❌❌❌Assertion Failed: ${actual} !== ${expected}`); // } // }; // assertEqual(findKey({ // "Blue Hill": { stars: 1 }, // "Akaleri": { stars: 3 }, // "noma": { stars: 2 }, // "elBulli": { stars: 3 }, // "Ora": { stars: 2 }, // "Akelarre": { stars: 3 } // }, x => x.stars === 2), "noma"); module.exports = findKey;