Implemented calculation for problem 15 in js