One commonly used sorting algorithm is called selection sort. Here's how it works:
(Don't take the word "step" too literally; you'll probably see when you write the code that at least steps 3-4 are in a single report
block.)
sort
block with no help at all, do it now.
Otherwise you can click here.sort
block in Snap!, you'll need code for a base case, and code that follows the steps of the selection sort.
earliest in
block. For names, this returns the first name alphabetically in a list:min
block that takes two inputs and reports whichever is smaller. (You've done this before, but it's probably quicker to do it again than to find it in some earlier project and import it.) earliest
block using combine
.keep
if you assume that there are no equal items in the list. That's fine for now, although a correct sorting algorithm will keep all duplicate items in the result.sort
block should report a new sorted version of the list, without changing the original list. Sometimes it's okay to modify the original list, but sometimes it isn't, so go for the most generally useful solution.
sort
.
sort
call itself?
bjc.edc.org/June2020bjc2/bjc-r/cur/programming/3-lists/2-sorting/yob2014.txt
split
.map
used in part (d) but not in part (c)?set
isn't the most beautiful style, although it's great for explaining the steps. Over time, try to develop the habit of doing this instead:names starting with
.