Improve readability of javascript solution to Problem 8