solves problem001 in JavaScript and passes tests