From 89e031f27e3418e6836505671617562be3c8e0e4 Mon Sep 17 00:00:00 2001 From: marleyrae Date: Tue, 27 Jun 2023 18:58:53 -0700 Subject: [PATCH] Write .findKey() --- lodash/_.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lodash/_.js b/lodash/_.js index 9f27bd8..8634e19 100644 --- a/lodash/_.js +++ b/lodash/_.js @@ -54,5 +54,17 @@ _.invert = function (obj) { return newObj } +/* ------------------------------------------------------------- findKey ---- */ + +_.findKey = function (obj, cb) { + for (const key in obj) { + if (cb(obj[key])) { + return key + } + } + + return undefined +} + // Do not write or modify code below this line. module.exports = _