Convert Number to Words (Hard)
Good morning! Here's our prompt for today.
You may see this problem at Slack, Dropbox, Two Sigma, Procore, Airtable, Lucid Software, Fastly, Zoom, Sailpoint, and Okta.
Can you convert a number to its text equivalent? This is otherwise known as number spelling
.

For example, given 1234
, we expect to get "one thousand two hundred and thirty four"
back.
Constraints
- The given number will have <=
100
digits - Let n be the number of digits
- Expected time complexity :
O(n)
- Expected space complexity :
O(n)
xxxxxxxxxx
18
var assert = require('assert');
function numberToWords(n) {
// convert n to words
return n;
}
try {
assert.equal(numberToWords(1234), 'one thousand two hundred and thirty four');
console.log(
'PASSED: ' +
"assert.equal(numberToWords(1234), 'one thousand two hundred and thirty four');"
);
} catch (err) {
console.log(err);
}
OUTPUT
Results will appear here.