Last active
June 27, 2016 15:18
-
-
Save gr0uch/e01c035c4b2ec3f2da1e74e37530ff35 to your computer and use it in GitHub Desktop.
Revisions
-
0x8890 revised this gist
Jun 27, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ * ``` * * @param {Object} obj * @param {String|Number[]} path * @return {*} */ function walk (obj, path) { -
0x8890 revised this gist
Jun 17, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ function walk (obj, path) { for (i = 0, j = path.length; i < j; i++) { key = path[i] if (typeof result === 'object' && result !== null && key in result) result = result[key] else { result = void 0 -
0x8890 revised this gist
Jun 17, 2016 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,8 @@ function walk (obj, path) { for (i = 0, j = path.length; i < j; i++) { key = path[i] if (result !== null && typeof result === 'object' && key in result) result = result[key] else { result = void 0 break -
0x8890 created this gist
Jun 17, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ /** * Given an object and an array of keys, walk over the keys on the object. * * For example: * ```js * walk({ a: { b: [ 0, { c: 2 } ] } }, [ 'a', 'b', 1, 'c' ]) // returns 2 * ``` * * @param {Object} obj * @param {String[]|Number[]} path * @return {*} */ function walk (obj, path) { var result = obj var i, j, key for (i = 0, j = path.length; i < j; i++) { key = path[i] if (key in result) result = result[key] else { result = void 0 break } } return result }