Skip to content

Instantly share code, notes, and snippets.

View johnnycopes's full-sized avatar
💭
🙋‍♂️ What's cookin'?

John Coppola johnnycopes

💭
🙋‍♂️ What's cookin'?
View GitHub Profile
@johnnycopes
johnnycopes / countUniqueValues.js
Last active January 27, 2022 16:50
Algorithm exploration: Count Unique Values
/*
This algorithm challenge came up in Colt Steele's "JavaScript Algorithms and Data Structures" course:
Implement a function called `countUniqueValues` which accepts a sorted array and counts the unique values in the array.
There can be negative numbers in the array, but it will always be sorted.
Example output:
```
countUniqueValues([1, 1, 1, 1, 1, 2]); // 2
countUniqueValues([1, 2, 3, 4, 4, 4, 7, 7, 12, 12, 13]); // 7