Write a function to sort an array of integers in ascending order.
[3, 7, 2, 1, 6]
Write a function to sort an array of integers in ascending order.
[3, 7, 2, 1, 6]
user
def sort_ascending(arr): 
    for i in range(len(arr)): 
        for j in range(i + 1, len(arr)): 
            if arr[i] > arr[j]: 
                arr[i], arr[j] = arr[j], arr[i] 
    return arr 

# Driver Code 
arr = [3, 7, 2, 1, 6] 
print(sort_ascending(arr)) 
# Output: [1, 2, 3, 6, 7]
assistant
Here's a function in JavaScript that sorts an array of integers in ascending order:

```javascript
function sortAscending(arr) {
  return arr.sort(function(a, b) {
    return a - b;
  });
}

// Example usage:
const arr = [3, 7, 2, 1, 6];
const sortedArr = sortAscending(arr);
console.log(sortedArr); // [1, 2, 3, 6, 7]
```

The `sortAscending` function takes an array `arr` as its argument and returns a new sorted array.

Inside the function, we use the `sort` method of the array to sort its elements. The `sort` method takes a comparison function as its argument, which determines the order of the elements.

The comparison function we use is a simple one that subtracts the two elements being compared (`a` and `b`) and returns the result. If `a` is less than `b`, the function returns a negative number, which means `a` should come before `b` in the sorted array. If `a` is greater than or equal to `b`, the function returns a positive number, which means `a` should come after `b` in the sorted array.

Finally, we return the sorted array.

To use the function, simply call it with an array of integers as its argument, like we did in the example usage. The function will return a new sorted array with the elements in ascending order.
Write a function to sort an array of integers in ascending order.
[3, 7, 2, 1, 6]
user
def sort_ascending(arr): 
    for i in range(len(arr)): 
        for j in range(i + 1, len(arr)): 
            if arr[i] > arr[j]: 
                arr[i], arr[j] = arr[j], arr[i] 
    return arr 

# Driver Code 
arr = [3, 7, 2, 1, 6] 
print(sort_ascending(arr)) 
# Output: [1, 2, 3, 6, 7]
assistant
Write a function to sort an array of integers in ascending order.
[3, 7, 2, 1, 6]
user
def sort_ascending(arr): 
  # Sort the array by first taking the smallest element
  arr.sort() 

  # Return the sorted array
  return arr 

if __name__ == '__main__': 
  arr = [3, 7, 2, 1, 6]
  print(sort_ascending(arr)) # Output: [1, 2, 3, 4, 5]
assistant