Javascript String spacify()

Description

Javascript String spacify()



String.prototype.spacify = function( )
{
  return this.split('').join(' ');
};

Javascript String spacify()


String.prototype.spacify = function() {
  return this.split("").join(" ");
}
"ScriptOJ".spacify()

Javascript String spacify()

String.prototype.spacify = function () {
  return this.split('')
    .filter(e => e !== ' ')
    .join(' ');/*ww  w  .  j  ava 2s.  com*/
};

Javascript String spacify()

function spacify(str) {
      return str.split('').join(' ');
    }//w w  w.j  a va 2 s  .com

String.prototype.spacify = function(){
  return this.split('').join(' ');
}


console.log(spacify('hello world'));
console.log('hello world'.spacify());

Javascript String spacify()

// How would you modify the String prototype in Javascript
// so that it printed out spaces in between every character?

String.prototype.spacify = function() {
  var spaced = ''
  for (var i = 0; i < this.length-1; i++) {
    spaced += this[i] + ' '
  }//from w  w w.ja v  a 2  s  .co  m
  return spaced + this[i]
}

String.prototype.spacify2 = function() {
  return this.split('').join(' ');
}


var a = 'diana';
console.log(a.spacify() === a.spacify2())

Javascript String spacify()

// Add spacify to the String prototype
// 'hello world'.spacify ==> 'h e l l o  w o r l d'
String.prototype.spacify = function() {
  // Uses native version
  return this.split('').join(' ');
};



PreviousNext

Related