From a6bafe8f74144094d11a8a9aae6f08627a7ea0f8 Mon Sep 17 00:00:00 2001 From: Pavel Voitihovich Date: Tue, 17 Aug 2021 02:40:47 +0300 Subject: [PATCH] feat: complete task --- src/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index eeae09b1b..646e19a13 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,14 @@ module.exports = function toReadable (number) { - -} + //let hundreds = ['one hundred', 'two hundred', 'three hundred', 'four hundred', 'five hundred', 'six hundred', 'seven hundred', 'eight hundred', 'nine hundred']; + let units = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; + let dozens = ['twenty', 'thirty', 'fourty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']; + + let result = ''; + if (number.toString().length === 3) { + result += units[Math.trunc(number / 100) - 1] + ' hundred' + ' ' + dozens[(number.toString().slice(1, 2)) - 2] + ' ' + units[(number.toString().slice(2)) - 1]; + } + if (number.toString().length === 2) { + result += dozens[Math.trunc(number / 10) - 2] + ' ' + units[(number.toString().slice(1)) - 1]; + } + return result; +} \ No newline at end of file