【发布时间】:2018-09-07 12:06:43
【问题描述】:
//1. input words beginning and ending with a vowel are preserved in lowercase
//2. input words beginning with vowels and ending in a non vowel are translated to uppercase
//3. input words beginning with a non vowel and ending with a vowel are translated to a capitalized word (only first letter is uppercase)
//4. when printing the words, only two vowels are preserved per word (the first two)
//Output "i dont know Dude i AM not typing ALL OF this Nonsens text"
var str = "i dont know dude i am not typing all of this nonsense text";
console.log(str);
var res = str.split(" ");
console.log(res);
for(let i = 0; i<res.length;i++){
//checking words after spliting into single words
if((res[i].split("") && (res[0] ==== 'a'|| 'e' || 'o' || 'u' || 'i' || 'y') && (/* last charachter to check */ ))
}
我是初学者 JavaScript 开发人员,我的练习遇到了一些困难,我有以上 4 个条件,首先我将数组拆分为一个单词,然后我希望拆分为单个字符,因此 res[0] 将是我的第一个项目。我不知道这是否可行,但至少我需要尝试。即使使用正则表达式,任何帮助都将不胜感激。谢谢
【问题讨论】:
-
根据第四个条件,“废话”会被转换成“废话”,对吧?
标签: javascript arrays replace split