Spec Smith — JavaScript

Read Pak RT's letter and write the function while villagers queue at your porch with edge cases: 6 levels of spec reading and TDD.

What the levels ask

  1. Write a function longest(words) that takes an array of strings and returns the LONGEST string. If the array is empty, return the empty string "". If several are equally long, return the first one.
  2. The function commonPrefix(a, b) returns the longest prefix the two strings SHARE. If they share no start at all, return "". Uppercase and lowercase letters count as different.
  3. The function sum(nums) adds up every number in the array. Skip values that are not numbers (strings, null, undefined). An empty array → 0.
  4. The function isPalindrome(s) returns true when the string reads the same from the front and from the back, and false when it doesn't. Ignore spaces and capital letters. An empty string counts as true.
  5. The function group(items, key) returns an object that groups the items by item[key]. An empty array → an empty object {}. Items that don't have that key go into the group "_".
  6. The function collapseRuns(arr) takes an array and returns a NEW array: equal values in a row are merged into one. An empty array → an empty array. [1, 1, 2, 2, 2, 1] → [1, 2, 1].