Files
30-seconds-of-code/test/dig/dig.js
2018-07-14 19:42:20 +00:00

8 lines
226 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;