Javascript String whitespace=function()

Description

Javascript String whitespace=function()


//Implement String#whitespace?(str) (Ruby), String.prototype.whitespace(str) (JavaScript), String::whitespace(str) (CoffeeScript), or whitespace(str) (Python), which should return true/True if given object consists exclusively of zero or more whitespace characters, false/False otherwise.

String.prototype.whitespace=function(){
  console.log(this);//  www .  j a v a2 s.  com
  return (/^[\s\r\n]+$/.test(this) || this.length === 0);
};



PreviousNext

Related