1

I want a function that will add a random symbol at the end of each sentence and remove all vowels. I know sentences could end with a ! or ? but lets just say these sentences will only end with a period. Each symbol has to be different I already inserted a asterisk to the end of the last sentence. How do I add a different symbol to the end of each sentence? This is what I have so far

function txtMod(str){
    var vowels = /[aioue]/gi ;
    var words = str.split(" ");
    words.splice(words.length,2,"*");
    var join = words.join(" ");
    var toStr = join.toString();
    return toStr.replace(vowels'');
}
txtMod("Hello world. This is just a test.");
4

2 に答える 2

0

単純なランダム文字ジェネレーターを使用Math.randomして乱数を生成し、その数値を使用して文字列または配列にインデックスを付けます。例

function randomChar () {
    var template="!@#$%^&*";
    return template.charAt(Math.floor(Math.random()*template.length))
}

次に、その文字を文字列の末尾に追加します。

return txtMod(some_string) + randomChar() + randomChar();
于 2013-09-30T07:40:41.023 に答える