Javascript Technical Test - Algorithmic