Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- TABLESPACE
- isSquare
- Debug
- TypeScript
- codewar
- codewars
- java api
- react
- custom hook
- descendingOrder
- manifest.json
- react hook
- useEffect
- IBM
- type
- DB2
- JDBC
Archives
- Today
- Total
taesik
Implement a function called countUniqueValues(pointers pattern) 본문
functions and trick/typescript_javascript
Implement a function called countUniqueValues(pointers pattern)
taesikk 2022. 4. 29. 10:56Implement 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.
function countUniqueValues(arr) {
if(arr.length ===0) return 0;
let i =0;
for(let j=1; j<arr.length; j++) {
if(arr[i] !== arr[j]){
i++;
arr[i] = arr[j];
}
}
return i+1;
}