Here you can find the source of substrings()
String.prototype.substrings = function () { let substrings = [];//from w ww . j a v a2 s . c o m 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; }; // let a = "cat"; // console.log(a.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;
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; };
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; }; ...
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; }; ...
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());
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.slice(start, start + len)); return substrings; }; ...
String.prototype.substrings = function () { var substrings = []; for (var i = 0; i < this.length; i++) { for (var j = i + 1; j <= this.length; j++) { var sub = this.slice(i,j); if (substrings.indexOf(sub) === -1 ) { substrings.push(sub); return substrings; }; console.log("cat".substrings());
String.prototype.substrings = function () { results = [] for (i = 0; i < this.length; i++ ) { for (j = i + 1; j <= this.length; j++ ) { var cur_substr = this.substring(i, j); var includes = false; for (k = 0; k < results.length; k++ ) { if (results[k] === cur_substr) { includes = true; ...
String.prototype.substrings = function() { var substrings = []; for (var i = 0; i < this.length; i++){ for (var j = i; j < this.length; j++){ substrings.push(this.slice(i,j+1)); }; }; return substrings; console.log(("cat").substrings());