This is a correct and efficient solution.
In reply to Re^2: One for the weekend: challenge by BrowserUk in thread One for the weekend: challenge by BrowserUk