Added lab3

This commit is contained in:
Oleh 2023-05-13 21:49:49 +02:00
parent ab62df0a7f
commit 6d7a81dee2
1 changed files with 23 additions and 0 deletions

23
src/lab3.js Normal file
View File

@ -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())