Skip to content

Commit

Permalink
add recursion demo b00tc4mp#163
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbarzi committed Oct 3, 2024
1 parent 3850cae commit 8e42048
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions stuff/js/recursion/for-each.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var ns = [100, 200, 300]

/*
for (var i = 0; i < ns.length; i++)
console.log(ns[i])
*/

//ns.forEach(function(n) { console.log(n) })

var forEach = function (array, index) {
if (index === undefined) index = 0

console.log(array[index])

if (index < array.length - 1)
forEach(array, index + 1)
}

forEach(ns)

0 comments on commit 8e42048

Please sign in to comment.