Last active
January 30, 2017 05:46
-
-
Save basekays/57c5fd6655c5c86ef63d5b776d6ac305 to your computer and use it in GitHub Desktop.
recursion.js
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 characters
| var getElementsByClassName = function(className, n) { | |
| // your code here | |
| var resultArr = []; | |
| var searchClass = function(element) { | |
| if (element.classList) { | |
| if (element.classList.contains(className)) { | |
| resultArr.push(element); | |
| } | |
| } | |
| for (var i = 0; i < element.childNodes.length; i++) { | |
| searchClass(element.childNodes[i]); | |
| } | |
| } | |
| searchClass(document.body); | |
| return resultArr; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment