JSFiddle - React, Tailwind, and code Playground

by Diana Lemen

JavaScript

const A = [5,2,4,6,1,3];
const B = [];
B.push(A[0]);
for(let j = 2; j <= A.length; j++) {
  let i = j - 1;
	let key = A[i];
  B.push(key);
  let y = B.length - 1;
  while(B[y] < B[y-1]) {
    const a = B[y];
    const b = B[y - 1];
    B[y - 1] = a;
    B[y] = b;
    y--;
 }
}
console.log(B);