Javascript String mySubStrings()

Description

Javascript String mySubStrings()

String.prototype.mySubStrings = function() {
  result = [];//www .j  av  a2s.  c  o  m

  for( var i = 0; i < this.length; i++){
    for( var j=i+1 ; j < this.length + 1; j++ ){
      result.push(this.substring(i, j));
    }
  }
  return result;
};

Javascript String mySubstrings()

String.prototype.mySubstrings = function() {

  let substrings = []

  for (let i = 0; i <= this.length; i++ ) {
    for (let j = i + 1; j <= this.length; j++ ) {
      substrings.push(this.slice(i, j))/*from  w ww . java2s.  c o m*/
    }
  }
  return substrings
}

console.log("Cat".mySubstrings())



PreviousNext

Related