Last active
December 6, 2021 08:06
-
-
Save haase1020/af6d0f7f3a93a9a11a017ab3519f8999 to your computer and use it in GitHub Desktop.
clean house recursive function
This file contains 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
const todoList = [ | |
"pick up the floor", | |
"clear the table", | |
"put away dishes", | |
"sweep", | |
"clean the bathrooms", | |
"dust", | |
"mop", | |
]; | |
function cleanHouse(list) { | |
console.log(list); // notice the array changes with each recursive call | |
if (list.length === 0) { | |
console.log("Great job! House cleaning is done ✨"); | |
return; // you need this return to stop running the function! | |
} | |
cleanHouse(list.slice(1)); | |
} | |
console.log(cleanHouse(todoList)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment