Attentive interview question

Asked to write a function