john sokpo

Generation

generate functionThu, 06 Jul 2023

Convert a non-negative integer num to its English words representation.

Script /** * @param {number} num * @return {string} */ var numberToWords = function(num) { if (num === 0) { return 'Zero'; } const units = ['', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen']; const tens = ['', 'Ten', 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety']; const thousands = ['', ' Thousand ', ' Million ', ' Billion ']; let result; for (let i = 0; i < thousands.length; i++) { if (num % 1000 !== 0) { result = helper(num % 1000) + thousands[i] + (result || ''); } num = parseInt(num

Want to kickstart your project?Use the new AI Studio to create your code