I have arrays like this one below.
[1,2,3, 10, 15, 24,25,26,27]
What I want is to filter out the non consecutive numbers excluding the first number in a series but keeping the last in a series like this below.
[2,3, 25,26,27]
I am new to coding and I'm not sure how to write this code yet but I have mocked up pseudocode, would you check this and see if my logic is on track?
Var startArray = [1,2,3, 10, 15, 24,25,26,27];
Var endArray = [ ];
Loop: while there are numbers left in the start array
GET: The first number of the startArray
IF: the first number is 1
MOVE: to next number in the array
IF: the current number + 1 in the array subtracted by the current number -1 in the array === 2
PUSH: current number into endArray
ELSE IF: the current number -1 ===1
PUSH: current number into endArray
END IF
END LOOP
Thank you for your help.