Question d’entretien chez Apple

Write a function that passes the tests below.