+ 1
Create a function disp3char which takes a string as a parameter and displays all the 3 letter words of the sentence.
example: entered string is Hii rahul you are a nice person. output: Hii you are
2 Respuestas
+ 1
Javascript:
function disp3char(string){
string = string || "There was no input";
const allWords = string.split(" "),
words = allWords.filter(function(element){
return element.length === 3;
});
console.log(words.join(" "));
}
Warning: this may throw errors if there are less than 3 words.
0
JavaScript:
const disp3char = s => s.split(' ').filter(x => x.length === 3).join(' ');
RegEx (all 3-letter words in group 1):
/(?:(?:(\w{3})(?:\s+|$))|(?:\w+\s*?))/img
The RegEx works on regex101.com but not in the JS regex engine.