AutoNation interview question

I was given a problem to solve it with code (Javascript)