refactored create function to sort array
update function sortArray