制作 pilatin 转换器的麻烦
Trouble with making a piglatin converter
好的,所以我在尝试删除第一个元音之前的所有内容,将其添加到末尾,然后将 "ay" 添加到那个
的末尾时遇到了一些麻烦
function translate(word) { // put first constants at end && add "ay"
var result = word;
var end = "WillBeOverrideN";
for (var i = 0; i < result.length; i++) {
if (result.charAt(i) === ("a" || "e" || "i" || "o" || "u")) {
end = result.slice(0, i-1); // everything b/f vowel
result = result.slice(i-1); // everything after && vowel
result += end;
break;
}
}
result += "ay";
return result;
}
你必须稍微改变一下功能,
这是工作函数
function translate(word) { // put first constants at end && add "ay"
var result = word;
var last = "WillBeOverrideN";
for (var i = 0; i < result.length; i++) {
if(["a","e","i","o","u"].indexOf(result[i]) !== -1){
last = result.slice(0, i); // everything b/f vowel
result = result.slice(i); // everything after && vowel
result += last ;
break;
}
}
result += "ay";
return result;
}
好的,所以我在尝试删除第一个元音之前的所有内容,将其添加到末尾,然后将 "ay" 添加到那个
的末尾时遇到了一些麻烦 function translate(word) { // put first constants at end && add "ay"
var result = word;
var end = "WillBeOverrideN";
for (var i = 0; i < result.length; i++) {
if (result.charAt(i) === ("a" || "e" || "i" || "o" || "u")) {
end = result.slice(0, i-1); // everything b/f vowel
result = result.slice(i-1); // everything after && vowel
result += end;
break;
}
}
result += "ay";
return result;
}
你必须稍微改变一下功能, 这是工作函数
function translate(word) { // put first constants at end && add "ay"
var result = word;
var last = "WillBeOverrideN";
for (var i = 0; i < result.length; i++) {
if(["a","e","i","o","u"].indexOf(result[i]) !== -1){
last = result.slice(0, i); // everything b/f vowel
result = result.slice(i); // everything after && vowel
result += last ;
break;
}
}
result += "ay";
return result;
}