🔄 distinctUntilChanged() Polyfill
Category: js / utils
Difficulty: easy
The distinctUntilChanged() method filters out consecutive duplicate values from an array, similar to the RxJS operator. It only removes duplicates that appear next to each other, preserving non-consecutive duplicates. ✅ Implementation [code example] Usage: [code example] <!-- quiz-start --> Q1: What does distinctUntilChanged do with the array [1, 2, 2, 1, 1, 2]? [ ] Returns [1, 2] [x] Returns [1, 2, 1, 2] [ ] Returns [1, 2, 2, 1, 1, 2] [ ] Returns [1, 1, 2, 2] Q2: How does distinctUntilChanged differ from removing all duplicates? [ ] It's faster than removing all duplicates [ ] It only works with numbers [x] It only removes consecutive duplicates, preserving non-consecutive ones [ ] It modifies the original array Q3: What is the result of [1, 1, 1, 1].distinctUntilChanged()? [x] [1] [ ] [] [ ] [1, 1, 1, 1] [ ] undefined <!-- quiz-end -->