News for hackers. Stuff that matters.
Re:Crystal 0.28.0 Released by silly_giraffe on Thursday April 18, 2019 @10:49PM (#19696705)
>same stuff within the standard library, like list.sort() and sorted(list)

Those have different use cases. `sorted` is for situations where you would use a list comprehension and immediately consume the result vs `.sort` where you need the iterable sorted for future use.

As a quick scribble, you can do something like the following to sort random numbers in a single line:

  result = sorted(random.random() for x in range(10))
From your Medium post:

  def list_sort(arr):
    return arr.sort()

  def sorted_builtin(arr):
    return sorted(arr)
Only the `sorted_builtin` function returns the array, `list_sort` returns None. The `list_sort` function would have to become:

  def list_sort(arr):
    arr.sort()
    return arr
Edit: goofed the formatting

There are no comments on this comment yet.