Files
30-seconds-of-code/test/dig/dig.js
2018-07-13 11:21:21 -07:00

16 lines
336 B
JavaScript

const dig = (obj, target) =>
target in obj
? obj[target]
: Object
.values(obj)
.reduce((acc, val) => {
if (acc !== undefined) {
return acc;
}
if (typeof val === "object") {
return dig(val, target);
}
}, undefined);
module.exports = dig;