param { number } n return { number } function TheNOfTheUglyNumber ( n ) { if ( n <= 0 ) { return 0 ; } let uglyNumbers = [ 1 ] ; let nextUglyIndex = 1 ; let ugly2 = 0 , ugly3 = 0 , ugly5 = 0 ; while ( nextUglyIndex < n ) { let min = Math . min ( uglyNumbers [ ugly2 ] * 2 , uglyNumbers [ ugly3 ] * 3 , uglyNumbers [ ugly5 ] * 5 ) ; uglyNumbers [ nextUglyIndex ] = min ; while ( uglyNumbers [ ugly2 ] * 2 <= min ) ugly2 ++ ; while ( uglyNumbers [ ugly3 ] * 3 <= min ) ugly3 ++ ; while ( uglyNumbers [ ugly5 ] * 5 <= min ) ugly5 ++ ; nextUglyIndex ++ ; } return uglyNumbers [ nextUglyIndex - 1 ] ; } export { TheNOfTheUglyNumber } ;