fork download
  1. // your code goes here
  2. function find(object, path) {
  3. var result = [];
  4. var currentPath = path.split(".");
  5. for (var i = 0; i < currentPath.length; i++) {
  6. for (var key in object) {
  7. if (currentPath[i] == key) {
  8. result.push(currentPath[i]);
  9. }
  10. if (typeof(object[key]) == "object") {
  11. var objectKeys = Object.keys(object[key]);
  12. for (var j = 0; j < objectKeys.length; j++) {
  13. if (currentPath[i] == objectKeys[j]) {
  14. result.push(currentPath[i]);
  15. }
  16. }
  17. }
  18. }
  19. }
  20.  
  21.  
  22.  
  23. var res = result.reduce(function(sum, iteam) {
  24. return sum[iteam];
  25. }, object);
  26. return res;
  27. }
Success #stdin #stdout 0.02s 10660KB
stdin
Standard input is empty
stdout
Standard output is empty