Files
30-seconds-of-code/test/dig/dig.js
2018-07-14 10:59:56 +03:00

10 lines
228 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;