Nodejs String Sub String substrings()

Here you can find the source of substrings()

Method Source Code

String.prototype.substrings = function () {
    const res = [];//from   w  ww.  j ava 2s  .c om
    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;
};

Related

  1. 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());
    
  2. 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));
      return substrings;
    };
    ...
    
  3. 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;
    };
    ...
    
  4. 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;
    };
    
  5. 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;
    
  6. substrings()
    String.prototype.substrings = function() {
      var subs = [];
      for(var i = 0; i < this.length; i++) {
        for(var j = i + 1; j <= this.length; j++) {
          subs.push(this.slice(i, j));
      return subs;
    };
    ...
    
  7. substrings()
    String.prototype.substrings = function () {
      let substrings = [];
      for (let start = 0; start < this.length; start++) {
        for (let len = 1; (start + len) <= this.length; len++) {
          substrings.push(this.substring(start, start + len));
      return substrings;
    };
    ...
    
  8. substrings()
    String.prototype.substrings = function() {
      var substrings = []
      for (var i1 = 0; i1 < this.length; i1++) {
        for (var i2 = i1; i2 < this.length; i2++) {
          substrings.push(this.substr(i1, i2 + 1));
      return substrings;
    console.log("abc".substrings());
    
  9. substrings()
    String.prototype.substrings = function () {
      let substrings = [];
      let chars = this.split('');
      for (let i = 0; i <= chars.length; i++) {
        for (let j = i + 1; j <= chars.length; j++) {
          let substring = chars.slice(i, j);
          substrings.push(substring.join(''));
      return substrings;
    };