Mini-exercises

  1. Create a constant array called names which contains some names as strings (any names will do — make sure there’s more than three though!). Now use reduce to create a string which is the concatenation of each name in the array.
  2. Using the same names array, first filter the array to contain only names which have more than four characters in them, and then create the same concatenation of names as in the above exercise. (Hint: you can chain these operations together.)
  3. Create a constant dictionary called namesAndAges which contains some names as strings mapped to ages as integers. Now use filter to create a dictionary containing only people under the age of 18.
  4. Using the same namesAndAges dictionary, filter out the adults (those 18 or older) and then use map to convert to an array containing just the names (i.e. drop the ages).

results matching ""

    No results matching ""