Skip to content

Instantly share code, notes, and snippets.

@llekn
Last active October 5, 2023 19:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save llekn/4aa027216eb38a755c5011e3cec82ab1 to your computer and use it in GitHub Desktop.
Save llekn/4aa027216eb38a755c5011e3cec82ab1 to your computer and use it in GitHub Desktop.
Wave Sort

Wave Sort

Dado un arreglo de números (por ejemplo [1, 2, 6, 19, 12, 3, 1]), crear la función wave_sort que ordene los elementos del arreglo "como serrucho". Esto es, el arreglo retornado debe cumplir con el siguiente criterio:

arr[0] >= arr[1] <= arr[2] >= arr[3] <= arr[4] >= ...

Una posible solución, para el caso del ejemplo es:

wave_sort([1, 2, 6, 19, 12, 3, 1])
=> [19, 1, 12, 1, 6, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment