Files
30-seconds-of-code/test/dig/dig.js
Henry Szeto fdcf0fb929 add test
2018-07-12 23:03:05 -07:00

11 lines
283 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;