我有一个可以从字符串中删除单词的函数。这是 :
var removeFromString = function(oldStr, fullStr) {
return fullStr.split(oldStr).join('');
};
我这样使用它:
console.log( removeFromString("Hello", "Hello World") ); // World
console.log( removeFromString("Hello", "Hello-World") ); // -World
但主要问题是:
var str = "Remove one, two, not three and four";
这里我们必须删除“一”、“二”和“四”。这可以通过以下方式完成:
var a = removeFromString("one, two,", str); // Remove not three and four
var b = removeFromString("and four", a); // Remove not three
console.log(b); // Remove not three
在上面的例子中,我不得不使用该函数两次。我希望它是这样的:
var c = removeFromString(["one, two," , "and four"], str); // Remove not three
console.log(c); // Remove not three
是的,我实际上想升级removeFromString函数!我怎样才能做到这一点 ?