Robinhood Interview Question

Complete a task in javascript.