JSFiddle - React, Tailwind, and code Playground

by kpulkit29

JavaScript

function insert(st, element) {
 if(!st.length) {
 		st.push(element);
    return
 }
  let tp = st.slice(-1)[0];
  st.pop();
  insert(st, element);
  st.push(tp);
}

function reverse(st) {
debugger
	if(!st.length) return;
  let tp = st.slice(-1)[0]
  st.pop();
  reverse(st);
  insert(st, tp);
}
let a = [1,2,3,4];
reverse(a)
console.log(a)