-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathunique_in_order.js
More file actions
28 lines (25 loc) · 1.83 KB
/
unique_in_order.js
File metadata and controls
28 lines (25 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/******************************************************************************************
* CODEWARS UNIQUE IN ORDER CHALLENGE *
* *
* Problem Statement *
* Implement the function unique_in_order which takes as argument a sequence and returns a*
* list of items without any elements with the same value next to each other & preserving *
* the original order of elements. *
* *
* Examples *
* Input 1: "AAAABBBCCDAABBB" *
* Output 1: ['A', 'B', 'C', 'D', 'A', 'B'] *
* *
* Input 2: "ABBCcAD" *
* Output 2: ['A', 'B', 'C', 'c', 'A', 'D'] *
* *
* Input 3: [1,2,2,3,3] *
* Output 3: [1, 2, 3] *
*****************************************************************************************/
var uniqueInOrder = function (iterable) {
let iterableArray = [];
for (let i = 0; i < iterable.length; i++) {
if (iterable[i] !== iterable[i + 1]) iterableArray.push(iterable[i]);
}
return iterableArray;
};