🌱 Recursion in JS

BAR

  • base case
  • action
  • recurse
const printElm = (arr) => {
  if (arr.length === 0) return
  console.log(arr[0])
  printElm(arr.slice(1))
}

const printElmR = (arr) => {
  if (arr.length === 0) return
  printElmR(arr.slice(1))
  console.log(arr[0])
}

arr = [1, 2, 3]

printElm(arr)
printElmR(arr)
Made by Brandon . If you find this project useful you can donate.