How to get all substrings (contiguous subsequences) of my JavaScript array?
Clash Royale CLAN TAG#URR8PPP
up vote
9
down vote
favorite
My task is to split the given array into smaller arrays using JavaScript. For example [1, 2, 3, 4]
should be split to [1] [1, 2] [1, 2, 3] [1, 2, 3, 4] [2] [2, 3] [2, 3, 4] [3] [3, 4] [4]
.
I am using this code:
let arr = [1, 2, 3, 4];
for (let i = 1; i <= arr.length; i++)
let a = ;
for (let j = 0; j < arr.length; j++)
a.push(arr[j]);
if (a.length === i)
break;
console.log(a);
And I get the following result: [1] [1, 2] [1, 2, 3] [1, 2, 3, 4] undefined
What am I missing/doing wrong?
javascript arrays substring
 |Â
show 1 more comment
up vote
9
down vote
favorite
My task is to split the given array into smaller arrays using JavaScript. For example [1, 2, 3, 4]
should be split to [1] [1, 2] [1, 2, 3] [1, 2, 3, 4] [2] [2, 3] [2, 3, 4] [3] [3, 4] [4]
.
I am using this code:
let arr = [1, 2, 3, 4];
for (let i = 1; i <= arr.length; i++)
let a = ;
for (let j = 0; j < arr.length; j++)
a.push(arr[j]);
if (a.length === i)
break;
console.log(a);
And I get the following result: [1] [1, 2] [1, 2, 3] [1, 2, 3, 4] undefined
What am I missing/doing wrong?
javascript arrays substring
I think you should set j=i in begin loop
– Alexandr Kudryashov
2 hours ago
@AlexandrKudryashov I have tried. It is not correct
– TeodorKolev
2 hours ago
set j=i and remove the if condition in the nested loop
– rock star
2 hours ago
init i with 0 and remove the = symbol in the corresponding condition
– rock star
2 hours ago
1
@rockstar nope, it is not correct
– TeodorKolev
2 hours ago
 |Â
show 1 more comment
up vote
9
down vote
favorite
up vote
9
down vote
favorite
My task is to split the given array into smaller arrays using JavaScript. For example [1, 2, 3, 4]
should be split to [1] [1, 2] [1, 2, 3] [1, 2, 3, 4] [2] [2, 3] [2, 3, 4] [3] [3, 4] [4]
.
I am using this code:
let arr = [1, 2, 3, 4];
for (let i = 1; i <= arr.length; i++)
let a = ;
for (let j = 0; j < arr.length; j++)
a.push(arr[j]);
if (a.length === i)
break;
console.log(a);
And I get the following result: [1] [1, 2] [1, 2, 3] [1, 2, 3, 4] undefined
What am I missing/doing wrong?
javascript arrays substring
My task is to split the given array into smaller arrays using JavaScript. For example [1, 2, 3, 4]
should be split to [1] [1, 2] [1, 2, 3] [1, 2, 3, 4] [2] [2, 3] [2, 3, 4] [3] [3, 4] [4]
.
I am using this code:
let arr = [1, 2, 3, 4];
for (let i = 1; i <= arr.length; i++)
let a = ;
for (let j = 0; j < arr.length; j++)
a.push(arr[j]);
if (a.length === i)
break;
console.log(a);
And I get the following result: [1] [1, 2] [1, 2, 3] [1, 2, 3, 4] undefined
What am I missing/doing wrong?
let arr = [1, 2, 3, 4];
for (let i = 1; i <= arr.length; i++)
let a = ;
for (let j = 0; j < arr.length; j++)
a.push(arr[j]);
if (a.length === i)
break;
console.log(a);
let arr = [1, 2, 3, 4];
for (let i = 1; i <= arr.length; i++)
let a = ;
for (let j = 0; j < arr.length; j++)
a.push(arr[j]);
if (a.length === i)
break;
console.log(a);
javascript arrays substring
javascript arrays substring
edited 13 mins ago
Bergi
346k54502823
346k54502823
asked 2 hours ago


TeodorKolev
96752043
96752043
I think you should set j=i in begin loop
– Alexandr Kudryashov
2 hours ago
@AlexandrKudryashov I have tried. It is not correct
– TeodorKolev
2 hours ago
set j=i and remove the if condition in the nested loop
– rock star
2 hours ago
init i with 0 and remove the = symbol in the corresponding condition
– rock star
2 hours ago
1
@rockstar nope, it is not correct
– TeodorKolev
2 hours ago
 |Â
show 1 more comment
I think you should set j=i in begin loop
– Alexandr Kudryashov
2 hours ago
@AlexandrKudryashov I have tried. It is not correct
– TeodorKolev
2 hours ago
set j=i and remove the if condition in the nested loop
– rock star
2 hours ago
init i with 0 and remove the = symbol in the corresponding condition
– rock star
2 hours ago
1
@rockstar nope, it is not correct
– TeodorKolev
2 hours ago
I think you should set j=i in begin loop
– Alexandr Kudryashov
2 hours ago
I think you should set j=i in begin loop
– Alexandr Kudryashov
2 hours ago
@AlexandrKudryashov I have tried. It is not correct
– TeodorKolev
2 hours ago
@AlexandrKudryashov I have tried. It is not correct
– TeodorKolev
2 hours ago
set j=i and remove the if condition in the nested loop
– rock star
2 hours ago
set j=i and remove the if condition in the nested loop
– rock star
2 hours ago
init i with 0 and remove the = symbol in the corresponding condition
– rock star
2 hours ago
init i with 0 and remove the = symbol in the corresponding condition
– rock star
2 hours ago
1
1
@rockstar nope, it is not correct
– TeodorKolev
2 hours ago
@rockstar nope, it is not correct
– TeodorKolev
2 hours ago
 |Â
show 1 more comment
6 Answers
6
active
oldest
votes
up vote
4
down vote
accepted
You have two issues in your code:
- You need to have loop to initialize with the value of
i
for the inner loop so that it consider the next index for new iteration ofi
- You need to remove that
break
on the length which you have in inner loop.
let arr = [1, 2, 3, 4];
for (let i = 0; i <= arr.length; i++)
let a = ;
for (let j = i; j < arr.length; j++)
a.push(arr[j]);
console.log(a);
add a comment |Â
up vote
7
down vote
For the inner array, you could just start with the index of the outer array.
var array = [1, 2, 3, 4],
temp,
i, j, l = array.length,
result = ;
for (i = 0; i < l; i++)
for (j = i; j < l; j++)
result.push(array.slice(i, j + 1));
console.log(result.map(a => a.join(' ')));
.as-console-wrapper max-height: 100% !important; top: 0;
1
I was expecting answer from you :)
– Ankit Agarwal
2 hours ago
This do one big array. Target is to create small arrays
– TeodorKolev
2 hours ago
what do you want with small arrays? instead of pushing, you could display the sub array.
– Nina Scholz
1 hour ago
add a comment |Â
up vote
2
down vote
Try this
let arr = [1, 2, 3, 4];
for (let i = 0; i <= arr.length; i++)
let a = ;
var tmp=i;
for (let j = tmp; j < arr.length; j++)
a.push(arr[j]);
console.log(a);
Why do you need thetmp
variable?
– Jenny O'Reilly
1 hour ago
you can do it without tmp variable=)
– Alexandr Kudryashov
1 hour ago
add a comment |Â
up vote
0
down vote
i have prepare stackblitz for this case.
let source = [1,2,3,4];
const output = ;
const arrayMultiplier = (source) =>
const eachValueArray = ;
source.forEach((item, index) =>
// Will push new array who will be sliced source array.
eachValueArray.push(source.slice(0, source.length - index));
);
//We reverse array to have right order.
return eachValueArray.reverse();
;
for(let i = 0; i <= source.length; i++)
output.push(...arrayMultiplier(source));
source.shift(); // Will recraft source array by removing first index.
//Don't forget last item.
output.push(source);
console.log(output);
Is not the most shorten solution but do the job
AvoidforEach
+push
, usemap
instead
– Bergi
18 mins ago
add a comment |Â
up vote
0
down vote
Use two iteration
- get slice array based on loop index.
- use sliced array and combine array element.
var arr = [1, 2, 3, 4];
let newArra =;
arr.map((x,i)=>
let remainArr = arr.slice(i);
return remainArr.forEach((y, r) => newArra.push(arr.slice(i).slice(0, r+1)))
)
newArra.forEach(x=> console.log(x))
add a comment |Â
up vote
0
down vote
If you don't want to mutate your array.
let arr = [1, 2, 3, 4];
let res = ;
for (let i = 0; i <= arr.length; i++)
let a = ;
for (let j = i; j < arr.length; j++)
a = [...a, arr[j]];
res = [...res, a];
console.log(res);
New contributor
Varun Arya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
You have two issues in your code:
- You need to have loop to initialize with the value of
i
for the inner loop so that it consider the next index for new iteration ofi
- You need to remove that
break
on the length which you have in inner loop.
let arr = [1, 2, 3, 4];
for (let i = 0; i <= arr.length; i++)
let a = ;
for (let j = i; j < arr.length; j++)
a.push(arr[j]);
console.log(a);
add a comment |Â
up vote
4
down vote
accepted
You have two issues in your code:
- You need to have loop to initialize with the value of
i
for the inner loop so that it consider the next index for new iteration ofi
- You need to remove that
break
on the length which you have in inner loop.
let arr = [1, 2, 3, 4];
for (let i = 0; i <= arr.length; i++)
let a = ;
for (let j = i; j < arr.length; j++)
a.push(arr[j]);
console.log(a);
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
You have two issues in your code:
- You need to have loop to initialize with the value of
i
for the inner loop so that it consider the next index for new iteration ofi
- You need to remove that
break
on the length which you have in inner loop.
let arr = [1, 2, 3, 4];
for (let i = 0; i <= arr.length; i++)
let a = ;
for (let j = i; j < arr.length; j++)
a.push(arr[j]);
console.log(a);
You have two issues in your code:
- You need to have loop to initialize with the value of
i
for the inner loop so that it consider the next index for new iteration ofi
- You need to remove that
break
on the length which you have in inner loop.
let arr = [1, 2, 3, 4];
for (let i = 0; i <= arr.length; i++)
let a = ;
for (let j = i; j < arr.length; j++)
a.push(arr[j]);
console.log(a);
let arr = [1, 2, 3, 4];
for (let i = 0; i <= arr.length; i++)
let a = ;
for (let j = i; j < arr.length; j++)
a.push(arr[j]);
console.log(a);
let arr = [1, 2, 3, 4];
for (let i = 0; i <= arr.length; i++)
let a = ;
for (let j = i; j < arr.length; j++)
a.push(arr[j]);
console.log(a);
answered 1 hour ago


Ankit Agarwal
20.8k41840
20.8k41840
add a comment |Â
add a comment |Â
up vote
7
down vote
For the inner array, you could just start with the index of the outer array.
var array = [1, 2, 3, 4],
temp,
i, j, l = array.length,
result = ;
for (i = 0; i < l; i++)
for (j = i; j < l; j++)
result.push(array.slice(i, j + 1));
console.log(result.map(a => a.join(' ')));
.as-console-wrapper max-height: 100% !important; top: 0;
1
I was expecting answer from you :)
– Ankit Agarwal
2 hours ago
This do one big array. Target is to create small arrays
– TeodorKolev
2 hours ago
what do you want with small arrays? instead of pushing, you could display the sub array.
– Nina Scholz
1 hour ago
add a comment |Â
up vote
7
down vote
For the inner array, you could just start with the index of the outer array.
var array = [1, 2, 3, 4],
temp,
i, j, l = array.length,
result = ;
for (i = 0; i < l; i++)
for (j = i; j < l; j++)
result.push(array.slice(i, j + 1));
console.log(result.map(a => a.join(' ')));
.as-console-wrapper max-height: 100% !important; top: 0;
1
I was expecting answer from you :)
– Ankit Agarwal
2 hours ago
This do one big array. Target is to create small arrays
– TeodorKolev
2 hours ago
what do you want with small arrays? instead of pushing, you could display the sub array.
– Nina Scholz
1 hour ago
add a comment |Â
up vote
7
down vote
up vote
7
down vote
For the inner array, you could just start with the index of the outer array.
var array = [1, 2, 3, 4],
temp,
i, j, l = array.length,
result = ;
for (i = 0; i < l; i++)
for (j = i; j < l; j++)
result.push(array.slice(i, j + 1));
console.log(result.map(a => a.join(' ')));
.as-console-wrapper max-height: 100% !important; top: 0;
For the inner array, you could just start with the index of the outer array.
var array = [1, 2, 3, 4],
temp,
i, j, l = array.length,
result = ;
for (i = 0; i < l; i++)
for (j = i; j < l; j++)
result.push(array.slice(i, j + 1));
console.log(result.map(a => a.join(' ')));
.as-console-wrapper max-height: 100% !important; top: 0;
var array = [1, 2, 3, 4],
temp,
i, j, l = array.length,
result = ;
for (i = 0; i < l; i++)
for (j = i; j < l; j++)
result.push(array.slice(i, j + 1));
console.log(result.map(a => a.join(' ')));
.as-console-wrapper max-height: 100% !important; top: 0;
var array = [1, 2, 3, 4],
temp,
i, j, l = array.length,
result = ;
for (i = 0; i < l; i++)
for (j = i; j < l; j++)
result.push(array.slice(i, j + 1));
console.log(result.map(a => a.join(' ')));
.as-console-wrapper max-height: 100% !important; top: 0;
answered 2 hours ago


Nina Scholz
158k1277136
158k1277136
1
I was expecting answer from you :)
– Ankit Agarwal
2 hours ago
This do one big array. Target is to create small arrays
– TeodorKolev
2 hours ago
what do you want with small arrays? instead of pushing, you could display the sub array.
– Nina Scholz
1 hour ago
add a comment |Â
1
I was expecting answer from you :)
– Ankit Agarwal
2 hours ago
This do one big array. Target is to create small arrays
– TeodorKolev
2 hours ago
what do you want with small arrays? instead of pushing, you could display the sub array.
– Nina Scholz
1 hour ago
1
1
I was expecting answer from you :)
– Ankit Agarwal
2 hours ago
I was expecting answer from you :)
– Ankit Agarwal
2 hours ago
This do one big array. Target is to create small arrays
– TeodorKolev
2 hours ago
This do one big array. Target is to create small arrays
– TeodorKolev
2 hours ago
what do you want with small arrays? instead of pushing, you could display the sub array.
– Nina Scholz
1 hour ago
what do you want with small arrays? instead of pushing, you could display the sub array.
– Nina Scholz
1 hour ago
add a comment |Â
up vote
2
down vote
Try this
let arr = [1, 2, 3, 4];
for (let i = 0; i <= arr.length; i++)
let a = ;
var tmp=i;
for (let j = tmp; j < arr.length; j++)
a.push(arr[j]);
console.log(a);
Why do you need thetmp
variable?
– Jenny O'Reilly
1 hour ago
you can do it without tmp variable=)
– Alexandr Kudryashov
1 hour ago
add a comment |Â
up vote
2
down vote
Try this
let arr = [1, 2, 3, 4];
for (let i = 0; i <= arr.length; i++)
let a = ;
var tmp=i;
for (let j = tmp; j < arr.length; j++)
a.push(arr[j]);
console.log(a);
Why do you need thetmp
variable?
– Jenny O'Reilly
1 hour ago
you can do it without tmp variable=)
– Alexandr Kudryashov
1 hour ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Try this
let arr = [1, 2, 3, 4];
for (let i = 0; i <= arr.length; i++)
let a = ;
var tmp=i;
for (let j = tmp; j < arr.length; j++)
a.push(arr[j]);
console.log(a);
Try this
let arr = [1, 2, 3, 4];
for (let i = 0; i <= arr.length; i++)
let a = ;
var tmp=i;
for (let j = tmp; j < arr.length; j++)
a.push(arr[j]);
console.log(a);
let arr = [1, 2, 3, 4];
for (let i = 0; i <= arr.length; i++)
let a = ;
var tmp=i;
for (let j = tmp; j < arr.length; j++)
a.push(arr[j]);
console.log(a);
let arr = [1, 2, 3, 4];
for (let i = 0; i <= arr.length; i++)
let a = ;
var tmp=i;
for (let j = tmp; j < arr.length; j++)
a.push(arr[j]);
console.log(a);
edited 2 hours ago
Sudhir Ojha
1,024313
1,024313
answered 2 hours ago


Alexandr Kudryashov
559213
559213
Why do you need thetmp
variable?
– Jenny O'Reilly
1 hour ago
you can do it without tmp variable=)
– Alexandr Kudryashov
1 hour ago
add a comment |Â
Why do you need thetmp
variable?
– Jenny O'Reilly
1 hour ago
you can do it without tmp variable=)
– Alexandr Kudryashov
1 hour ago
Why do you need the
tmp
variable?– Jenny O'Reilly
1 hour ago
Why do you need the
tmp
variable?– Jenny O'Reilly
1 hour ago
you can do it without tmp variable=)
– Alexandr Kudryashov
1 hour ago
you can do it without tmp variable=)
– Alexandr Kudryashov
1 hour ago
add a comment |Â
up vote
0
down vote
i have prepare stackblitz for this case.
let source = [1,2,3,4];
const output = ;
const arrayMultiplier = (source) =>
const eachValueArray = ;
source.forEach((item, index) =>
// Will push new array who will be sliced source array.
eachValueArray.push(source.slice(0, source.length - index));
);
//We reverse array to have right order.
return eachValueArray.reverse();
;
for(let i = 0; i <= source.length; i++)
output.push(...arrayMultiplier(source));
source.shift(); // Will recraft source array by removing first index.
//Don't forget last item.
output.push(source);
console.log(output);
Is not the most shorten solution but do the job
AvoidforEach
+push
, usemap
instead
– Bergi
18 mins ago
add a comment |Â
up vote
0
down vote
i have prepare stackblitz for this case.
let source = [1,2,3,4];
const output = ;
const arrayMultiplier = (source) =>
const eachValueArray = ;
source.forEach((item, index) =>
// Will push new array who will be sliced source array.
eachValueArray.push(source.slice(0, source.length - index));
);
//We reverse array to have right order.
return eachValueArray.reverse();
;
for(let i = 0; i <= source.length; i++)
output.push(...arrayMultiplier(source));
source.shift(); // Will recraft source array by removing first index.
//Don't forget last item.
output.push(source);
console.log(output);
Is not the most shorten solution but do the job
AvoidforEach
+push
, usemap
instead
– Bergi
18 mins ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
i have prepare stackblitz for this case.
let source = [1,2,3,4];
const output = ;
const arrayMultiplier = (source) =>
const eachValueArray = ;
source.forEach((item, index) =>
// Will push new array who will be sliced source array.
eachValueArray.push(source.slice(0, source.length - index));
);
//We reverse array to have right order.
return eachValueArray.reverse();
;
for(let i = 0; i <= source.length; i++)
output.push(...arrayMultiplier(source));
source.shift(); // Will recraft source array by removing first index.
//Don't forget last item.
output.push(source);
console.log(output);
Is not the most shorten solution but do the job
i have prepare stackblitz for this case.
let source = [1,2,3,4];
const output = ;
const arrayMultiplier = (source) =>
const eachValueArray = ;
source.forEach((item, index) =>
// Will push new array who will be sliced source array.
eachValueArray.push(source.slice(0, source.length - index));
);
//We reverse array to have right order.
return eachValueArray.reverse();
;
for(let i = 0; i <= source.length; i++)
output.push(...arrayMultiplier(source));
source.shift(); // Will recraft source array by removing first index.
//Don't forget last item.
output.push(source);
console.log(output);
Is not the most shorten solution but do the job
answered 1 hour ago
Yanis-git
1,3171217
1,3171217
AvoidforEach
+push
, usemap
instead
– Bergi
18 mins ago
add a comment |Â
AvoidforEach
+push
, usemap
instead
– Bergi
18 mins ago
Avoid
forEach
+ push
, use map
instead– Bergi
18 mins ago
Avoid
forEach
+ push
, use map
instead– Bergi
18 mins ago
add a comment |Â
up vote
0
down vote
Use two iteration
- get slice array based on loop index.
- use sliced array and combine array element.
var arr = [1, 2, 3, 4];
let newArra =;
arr.map((x,i)=>
let remainArr = arr.slice(i);
return remainArr.forEach((y, r) => newArra.push(arr.slice(i).slice(0, r+1)))
)
newArra.forEach(x=> console.log(x))
add a comment |Â
up vote
0
down vote
Use two iteration
- get slice array based on loop index.
- use sliced array and combine array element.
var arr = [1, 2, 3, 4];
let newArra =;
arr.map((x,i)=>
let remainArr = arr.slice(i);
return remainArr.forEach((y, r) => newArra.push(arr.slice(i).slice(0, r+1)))
)
newArra.forEach(x=> console.log(x))
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Use two iteration
- get slice array based on loop index.
- use sliced array and combine array element.
var arr = [1, 2, 3, 4];
let newArra =;
arr.map((x,i)=>
let remainArr = arr.slice(i);
return remainArr.forEach((y, r) => newArra.push(arr.slice(i).slice(0, r+1)))
)
newArra.forEach(x=> console.log(x))
Use two iteration
- get slice array based on loop index.
- use sliced array and combine array element.
var arr = [1, 2, 3, 4];
let newArra =;
arr.map((x,i)=>
let remainArr = arr.slice(i);
return remainArr.forEach((y, r) => newArra.push(arr.slice(i).slice(0, r+1)))
)
newArra.forEach(x=> console.log(x))
var arr = [1, 2, 3, 4];
let newArra =;
arr.map((x,i)=>
let remainArr = arr.slice(i);
return remainArr.forEach((y, r) => newArra.push(arr.slice(i).slice(0, r+1)))
)
newArra.forEach(x=> console.log(x))
var arr = [1, 2, 3, 4];
let newArra =;
arr.map((x,i)=>
let remainArr = arr.slice(i);
return remainArr.forEach((y, r) => newArra.push(arr.slice(i).slice(0, r+1)))
)
newArra.forEach(x=> console.log(x))
edited 1 hour ago
answered 1 hour ago
Anoop
18.8k94468
18.8k94468
add a comment |Â
add a comment |Â
up vote
0
down vote
If you don't want to mutate your array.
let arr = [1, 2, 3, 4];
let res = ;
for (let i = 0; i <= arr.length; i++)
let a = ;
for (let j = i; j < arr.length; j++)
a = [...a, arr[j]];
res = [...res, a];
console.log(res);
New contributor
Varun Arya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
0
down vote
If you don't want to mutate your array.
let arr = [1, 2, 3, 4];
let res = ;
for (let i = 0; i <= arr.length; i++)
let a = ;
for (let j = i; j < arr.length; j++)
a = [...a, arr[j]];
res = [...res, a];
console.log(res);
New contributor
Varun Arya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
If you don't want to mutate your array.
let arr = [1, 2, 3, 4];
let res = ;
for (let i = 0; i <= arr.length; i++)
let a = ;
for (let j = i; j < arr.length; j++)
a = [...a, arr[j]];
res = [...res, a];
console.log(res);
New contributor
Varun Arya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
If you don't want to mutate your array.
let arr = [1, 2, 3, 4];
let res = ;
for (let i = 0; i <= arr.length; i++)
let a = ;
for (let j = i; j < arr.length; j++)
a = [...a, arr[j]];
res = [...res, a];
console.log(res);
New contributor
Varun Arya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 32 mins ago
Yanis-git
1,3171217
1,3171217
New contributor
Varun Arya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 48 mins ago


Varun Arya
11
11
New contributor
Varun Arya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Varun Arya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Varun Arya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52363370%2fhow-to-get-all-substrings-contiguous-subsequences-of-my-javascript-array%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
I think you should set j=i in begin loop
– Alexandr Kudryashov
2 hours ago
@AlexandrKudryashov I have tried. It is not correct
– TeodorKolev
2 hours ago
set j=i and remove the if condition in the nested loop
– rock star
2 hours ago
init i with 0 and remove the = symbol in the corresponding condition
– rock star
2 hours ago
1
@rockstar nope, it is not correct
– TeodorKolev
2 hours ago