Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide readme.md with a link to nodejs 12 (https://nodejs.org/dist/v12.0.0/) #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ Write your code in `src/index.js.
4. Press the submit button and enjoy

### Notes
1. We recommend you to use nodejs of version 12 or lower. If you using are any of the features which are not supported by v12, the score won't be submitted.
1. We recommend you to use nodejs of version 12 (https://nodejs.org/dist/v12.0.0/) or lower. If you using are any of the features which are not supported by v12, the score won't be submitted.
2. Each of your test case is limited to 30 sec.
53 changes: 52 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
module.exports = function toReadable (number) {


if( isNaN(number) ) {

console.log(number + " - is not a number");

return undefined;
}

if (number == 0) return "zero";

var sign = '';

if (number < 0) {

sign = 'minus ';

number = Math.abs(number);
}

sNumber = number.toString().split("").reverse();

var result;

if (sNumber.length > 0) {

const numbers1to9 = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];

result = numbers1to9[ Number(sNumber[0]) ];

if (sNumber.length > 1) {

if (sNumber[1] == '1') {

const numbers10to19 = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'];

result = numbers10to19[ Number(sNumber[0]) ];

} else {

const dozens = ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];

result = (dozens[ Number(sNumber[1]) ] + ' ' + result).trim();

}

if (sNumber.length > 2) {

result = (numbers1to9[Number(sNumber[2])] + ' hundred ' + result).trim();
}
}
}
return sign + result;
}