DoorDash interview question

Implementing a function sort the array