solve prob52 javasciprt