From 6d7a81dee268ca0d676e10954ad0e79b92f895a6 Mon Sep 17 00:00:00 2001 From: Oleh Date: Sat, 13 May 2023 21:49:49 +0200 Subject: [PATCH] Added lab3 --- src/lab3.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/lab3.js diff --git a/src/lab3.js b/src/lab3.js new file mode 100644 index 0000000..ab72b1f --- /dev/null +++ b/src/lab3.js @@ -0,0 +1,23 @@ +//C17 = 2131 % 17 = 6; Відсортувати слова заданого тексту за зростанням кількості голосних літер. + +import create from 'prompt-sync'; +const prompt = create(); + +class Sentence { + constructor() { + this.sentence = prompt("Input sentence: "); + } + sort() { + const words = this.sentence.split(/[\s.?!,;]/).filter((word) => word); + const vowels = /[AaEeiOoUuYy]/g + const sortedWords = words.sort((first, second) => { + const vowelsOfFirstWord = first.match(vowels)? first.match(vowels): []; + const vowelsOfSecondWord = second.match(vowels)? second.match(vowels): []; + return vowelsOfSecondWord.length - vowelsOfFirstWord.length; + }); + return sortedWords.join(' '); + } +} + +const sentence = new Sentence; +console.log(sentence.sort()) \ No newline at end of file