Skip to main content

273.js

/** ------------------------------------------------------------------------------
*
* 273. Integer to English Words
* Topics: Recursion
* https://leetcode.com/problems/integer-to-english-words/description/?envType=daily-question&envId=2024-08-07
*
------------------------------------------------------------------------------ */
/**
* @param {number} num
* @return {string}
*/
var numberToWords = function (num) {
const range = ["Hundred", "Thousand", "Million", "Billion", "Trillion"]

let answer = ""
let chunk = []

const str = num.toString()
let start = str.length % 3
if (start !== 0) {
chunk.push(str.slice(0, start))
}
for (let i = start; i < str.length; i += 3) {
chunk.push(str.slice(i, i + 3))
}

console.log(chunk)

for (const s of chunk) {
}
}

console.log()

const translations = new Map([
[1000000000, "Billion"],
[1000000, "Million"],
[1000, "Thousand"],
[100, "Hundred"],
[90, "Ninety"],
[80, "Eighty"],
[70, "Seventy"],
[60, "Sixty"],
[50, "Fifty"],
[40, "Forty"],
[30, "Thirty"],
[20, "Twenty"],
[19, "Nineteen"],
[18, "Eighteen"],
[17, "Seventeen"],
[16, "Sixteen"],
[15, "Fifteen"],
[14, "Fourteen"],
[13, "Thirteen"],
[12, "Twelve"],
[11, "Eleven"],
[10, "Ten"],
[9, "Nine"],
[8, "Eight"],
[7, "Seven"],
[6, "Six"],
[5, "Five"],
[4, "Four"],
[3, "Three"],
[2, "Two"],
[1, "One"],
])