Robinhood interview question

Complete a task in javascript.