Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let original = [1, 1, 2, 3, 3, 4, 3, 3, 3, 5, 6, 6, 7]
- var result = [Int]()
- var previous = 0
- original.forEach { value in
- if value != previous {
- previous = value
- result.append(value)
- }
- }
- print(result)
- let result2 = original.reduce([]) { (array, value) -> [Int] in
- guard let last = array.last else {
- return [value]
- }
- return last == value ? array : array + [value]
- }
- print(result2 == result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement