Last active
August 29, 2015 14:22
-
-
Save diegocard/e18c8c4632b1488b688a to your computer and use it in GitHub Desktop.
Revisions
-
diegocard revised this gist
Jun 7, 2015 . 1 changed file with 19 additions and 19 deletions.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 @@ -21,25 +21,25 @@ function keyLookup(obj, string) { // Test: var testObj = { someStuff: 1, someObjectStuff: { arr: [1, 2, 3] }, a: { b: { func : function() { return 1; }, c: [ { test : { f : 1 } }, 1 ] } } } keyLookup(testObj, "test") // returns "a : b : c : 0 : test" -
diegocard revised this gist
Jun 7, 2015 . 1 changed file with 44 additions and 18 deletions.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 @@ -1,19 +1,45 @@ function keyLookup(obj, string) { if (_.isObject(obj)) { var path = null; _.find(obj, function(value, key) { if (_.isString(key) && key.includes(string)) { path = key.toString(); return true; } else if (_.isObject(value) && !_.isFunction(value)) { var foundKeyValueRec = keyLookup(value, string); // Call recursively if (foundKeyValueRec) { path = key + ' : ' + foundKeyValueRec; return true; } } }); return path; } } // Test: var testObj = { someStuff: 1, someObjectStuff: { arr: [1, 2, 3] }, a: { b: { func : function() { return 1; }, c: [ { test : { f : 1 } }, 1 ] } } } keyLookup(testObj, "test") // returns "a : b : c : 0 : test" -
diegocard renamed this gist
Jun 6, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
diegocard created this gist
Jun 6, 2015 .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,19 @@ keyLookup: function(obj, string) { if (_.isObject(obj)) { var path = null; _.find(obj, function(value, key) { if (_.isString(key) && key.includes(string)) { path = key.toString(); return true; } else if (_.isObject(value) && !_.isFunction(value)) { var foundKeyValueRec = keyLookup(value, string); // Call recursively if (foundKeyValueRec) { path = key + ' : ' + foundKeyValueRec; return true; } } }); return path; } }