javascript bubble sort
const bubbleSort = (arr) => { for (let i = 0; i < arr.length; i++) { for (let j = 0; j < arr.length - i; j++) { if (arr[j] > arr[j + 1]) { let tmp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = tmp; } } } return arr; }
javascript bubble sort
const bubbleSort = (arr) => { for (let i = 0; i < arr.length; i++) { for (let j = 0; j < arr.length - i; j++) { if (arr[j] > arr[j + 1]) { let tmp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = tmp; } } } return arr; }
bubble sort javascript
function bubblesort(array) { len = array.length; for (let i = 0; i < len; i++) { for (let j = 0; j < len - i; j++) { let a = array[j]; if (a != array[-1]) { var b = array[j + 1]; if (a > b) { array[j] = b; array[j + 1] = a; } } } } } let array = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]; bubblesort(array); console.log(array)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us