diff --git a/README.md b/README.md index 5cad1d8..8274b0d 100644 --- a/README.md +++ b/README.md @@ -36,3 +36,9 @@ Task | Solution Task | Solution -----| -------- [PassingCars](https://app.codility.com/programmers/lessons/5-prefix_sums/passing_cars/) | https://app.codility.com/demo/results/training9CQXVB-6SV/ + +## Lesson 6: Sorting + +Task | Solution +-----| -------- +[Distinct](https://app.codility.com/programmers/lessons/6-sorting/) | https://app.codility.com/demo/results/training8DYNNM-G5T/ diff --git a/lessons/Distinct.js b/lessons/Distinct.js new file mode 100644 index 0000000..9e30560 --- /dev/null +++ b/lessons/Distinct.js @@ -0,0 +1,13 @@ +// you can write to stdout for debugging purposes, e.g. +// console.log('this is a debug message'); + +function solution(A) { + let obj = {}; + + for (let i = 0; i < A.length; i++) { + const element = A[i]; + obj[element] = !obj[element] ? 1 : obj[element] + 1; + } + + return Object.keys(obj).length; +}