Good evening! Here's our prompt for today.
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)
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
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
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment
We'll now take you through what you need to know.
How do I use this guide?