-4

I want to split array something like this:

input: [a,b,c,d,e];

output: [[a,b], [b,c], [c,d], [d,e]];
Hussain Dehgamwala
  • 1,909
  • 2
  • 9
  • 5
  • tried anything? – Dinesh undefined Jun 19 '17 at 07:39
  • Nope!!! Confused @Dinesh – Hussain Dehgamwala Jun 19 '17 at 07:40
  • @HussainDehgamwala I am sure that you can find something to try.. Stat with a loop.. – Weedoze Jun 19 '17 at 07:42
  • 2
    Step 1: think about your problem, figure out what logical process would turn your input into your desired output. Step 2: think about what code you can write that will accomplish this and then write this code. Step 3: if your code doesn't work the way you intended and you can't see why, then post a question on Stackoverflow and **include your attempted code in the question** – Lennholm Jun 19 '17 at 07:45

1 Answers1

0

You can try:

var input = ['a','b','c','d','e'];
var output = [];
for (var i = 0; i < input.length; i += 1) {
        output[i] = [];
    output[i].push(input[i]);
    output[i].push(input[i + 1]);
}