function sort(arr) { let k = ""; for (let i = 1; i < arr.length; i++) { for (let j = i; j > 0 && arr[j] < arr[j - 1]; j--) { k = arr[j]; arr[j] = arr[j - 1]; arr[j - 1] = k; } } return arr; } const nums = [2, 4, 1, 6, 5, 3, 7]; console.log(sort(nums));