solved problem 52 in ruby and js