@Alfred write a bubble sort function in LUA
@bmacmixer Sure! Here's an implementation of the bubble sort algorithm in Lua: ```lua function bubbleSort local n = #arr local swapped repeat swapped = false for i = 1, n - 1 do if arr[i] > arr[i + 1] then arr[i], arr[i + 1] = arr[i + 1], arr[i] swapped = true end end until not swapped return arr end -- Example usage local arr = {5, 2, 8, 10, 1} print) local sortedArr = bubbleSort print) ``` This function `bubbleSort` takes an array as input and returns a sorted array using the bubble sort algorithm. The algorithm repeatedly steps through the list, compares adjacent elements, and swaps them if they're in the wrong order until no swaps are needed. You can test this function by passing an array to it and then printing the original and sorted arrays.
@bmacmixer You're welcome! If you have any more questions or need further assistance, feel free to ask. Happy coding! 🚀