Open the Animals Starter File and click "Run". In the Interactions Area (right), type animals-table
. Hit "Enter" to see the default view of the table.
Ordering a Table with sort
1 Mabel Lee wants to sort this table by age
(youngest-to-oldest). Juan Carlos wants to sort the table by pounds
(heaviest-to-lightest). What are some other ways we could sort the table?
a.
b.
Pyret has a function called sort
that will produce sorted Tables!
2 Test out sort(animals-table, "age", true)
in the Interactions Area. Try using false
instead of true
.
Complete the sentences below by circling the behavior you observed for each Boolean.
(a) |
in ascending order (from least to greatest) |
in descending order (from largest to smallest) |
(b) |
in ascending order (from least to greatest) |
in descending order (from largest to smallest) |
3 The Domain of sort
has three inputs. One of them is the table itself. Can you identify the data types of the other two?
# sort :: (Tabletable-name, column-name, order) -> Table
4 What code will sort the animals by alphabetical order of their names?
5 Did you use true
or false
? Explain why.
Summarizing a Column with count
Let’s explore another table function, beginning with its contract:
# count :: Table, String -> Table
6 What do you expect the code count(animals-table, "legs")
to produce?
 Type the code into the Interactions Area and click "Enter" to test it out.
7 How many animals had 4 legs?
8 Think of another question you might be able to answer by making a different table using the count
function.
9 Fill in the blanks with the code to make the table: function-name (table-name :: Table, column-name :: String)
10 Try using the count
function to summarize the pounds
column. Is the resulting summary useful? Why or why not?
11 Tables that summarize data with a count are commonly used in the real world. Write an example of where you’ve seen them before:
12 Newspapers often incorporate data into their reporting. How else might they display this information, besides using a table?
These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, 1738598, 2031479, and 1501927).
Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.