JSFiddle - React, Tailwind, and code Playground

by kuyabiye

JavaScript

// Resolves the path into objects iteratively (but looks eerily like recursion).
function resolvePath(root, path){
  return path.split('/').reduce(function(pathObject, pathName){
    // For each path name we come across, use the existing or create a subpath
    pathObject["/?" + pathName] = pathObject["/?" + pathName] || { on: function() {}};
    // Then return that subpath for the next operation
    return pathObject["/?" + pathName];
  // Use the passed in base object to attach our resolutions
  }, root);
}

  // On every path entry, resolve using the base object
  var goal = {x: "00"}
 resolvePath(goal, "deposit/withdraw");
 resolvePath(goal, "deposit/bonus");
  // Return the base object for suceeding paths, or for our final value

console.log(goal);