Uber Interview Question

Asked to code in JavaScript