Javascript String delete()

Description

Javascript String delete()


String.prototype.delete=function() {
  for(var e in arguments) {
    console.log(typeof arguments[e]);
    this.replace(arguments[e],'');
    console.log(this);/* ww w.j a  v  a  2  s  .  com*/
  }
  return this.valueOf();
}
console.log("Hello World123".delete(/h/gi, /[0-9]/g));

Javascript String delete()

// http://www.codewars.com/kata/ruplesjs-number-2-string-delete

String.prototype.delete = function () {  
  var str = this.toString();
  
  for(let i = 0; i < arguments.length; i++) {
    switch(typeof arguments[i]) {
      case 'string':    
        str = str.replace(new RegExp(arguments[i], 'g'), "");
        break;/* ww w.j a v a2s  .co m*/
      case 'object':
        str = str.replace(arguments[i], "");    
        break;    
    }     
  }  
  
  return str;  
}



PreviousNext

Related