Nodejs String Sub String substrings()

Here you can find the source of substrings()

Method Source Code

// Add a method to the String prototype to return a list of all substrings.

String.prototype.substrings = function () {
  var substrings = [];

  for (var start = 0; start < this.length; start++) {
    for (var len = 1; (start + len) <= this.length; len++) {
      substrings.push(this.slice(start, start + len));
    }/*from w  ww .java  2s.  com*/
  }

  return substrings;
};

Related

  1. substrWoR(c)
    String.prototype.substrWoR = function(c){
      var n=1,o=0;
      while(o!=n){
        s=this.substr(0,c+(o=n)-1);
        n=s.split("\r").length;
      return s;
    
  2. substrb(len)
    String.prototype.substrb = function(len){
      var str1;
      if(this.lengthb() <= len)
        return this;
      for(var i = len/2; i < this.length; i++)
        str1 = this.substr(0,i);
    ...
    
  3. substring(start, end)
    String.prototype.substring = function(start, end) {
      if (start < 0) {
        start = start + this.length;
      if (!end) {
        end = this.length;
      } else if (end < 0) {
        end = end + this.length;
      var s = "";
      for (var i = start, len = this.length; i < end && i < len; i++) {
        s += this[i];
      return s;
    };
    
  4. substrings()
    String.prototype.substrings = function () {
      subs = [];
      for(var i = 0; i < this.length; i++) {
        for( var j = i+1; j < this.length+1; j++) {
          subs.push(this.slice(i,j));
        };
      };
      return subs;
    };
    ...
    
  5. substrings()
    String.prototype.substrings = function(){
      var substrings = []
      for (var i=0; i<this.length; i++){
        for (var j=i+1; j<=this.length; j++){
          substrings.push(this.slice(i,j));
      return substrings;
    var str = 'cat';
    console.log(str.substrings());
    
  6. substrings()
    String.prototype.substrings = function(){
      var array = [];
      for(var i = 0; i < this.length - 1; i++ ){
        for(var j= i + 1; j <= this.length; j++){
          array.push(this.substring(i, j));
      return array;
    };
    ...
    
  7. substrings()
    String.prototype.substrings = function() {
      subs = [];
      for (var i=0; i<this.length; i++) {
        for(var j=i+1; j<=this.length; j++) {
          var sub = this.substring(i, j);
          if (subs.indexOf(sub) === -1) {
            subs.push(sub);
      return subs;
    };
    
  8. substrings()
    String.prototype.substrings = function(){
      var substrArr = [];
      for(var i = 0; i < this.length; i++){
        for(var j = i; j < this.length; j++){
          substrArr.push(this.slice(i, (j+1)));
      return substrArr;
    
  9. substrings()
    String.prototype.substrings = function () {
        const res = [];
        for (let i = 0; i < this.length; i++) {
          for (let j = i + 1; j <= this.length; j++) {
            let word = this.slice(i,j);
            if (!res.includes(word)){
              res.push(word);
        return res;
    };