-4

I want to split array something like this:

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

output: [[a,b], [b,c], [c,d], [d,e]];
4
  • tried anything? Commented Jun 19, 2017 at 7:39
  • Nope!!! Confused @Dinesh Commented Jun 19, 2017 at 7:40
  • @HussainDehgamwala I am sure that you can find something to try.. Stat with a loop.. Commented Jun 19, 2017 at 7: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 Commented Jun 19, 2017 at 7:45

1 Answer 1

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]);
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.