Nearform interview question

Just solve the code and write tests