Apple Interview Question

Write a function that passes the tests below.