Files
30-seconds-of-code/test/dig/dig.js
2018-10-18 23:38:01 +03:00

9 lines
253 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;