I'm trying to get a good grasp on recursion by implementing document.getElementsByClassName. I've made something that works but I'd like to know if there is some blatant refactoring that should be done or perhaps some not-so-edge cases that might break it.var getElementsByClassName = function(className){  var result = [];  function diveIn(motherNode, result, className){    var maNodes = motherNode.childNodes    for (var i = 0; i < maNodes.length; i++){        var classes = maNodes[i].classList || [];        classes.forEach(function(classy){            if (classy === className){                result.push(maNodes[i]);            }        })        if (maNodes[i].childNodes[0]){            diveIn(maNodes[i], result, className);        }    }  }  diveIn(document, result, className);  return result;};
Practicing recursion with getElementsByClassName
javascript;recursion;reinventing the wheel;dom