exercise 5 in js
problem 6 in ruby