Skip to content

Commit 97e7f1b

Browse files
committed
Shrink by using reduce
1 parent 3212139 commit 97e7f1b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export default function dlv(obj, key, def, p, undef) {
1+
export default function dlv(obj, key, def, undef) {
22
key = key.split ? key.split('.') : key;
3-
for (p = 0; p < key.length; p++) {
4-
obj = obj ? obj[key[p]] : undef;
5-
}
3+
obj = key.reduce(function(obj, p) {
4+
return obj ? obj[p] : undef;
5+
}, obj);
66
return obj === undef ? def : obj;
77
}

0 commit comments

Comments
 (0)