From 64bafa37b5c7246b26b38a06dbe3c25a901176ea Mon Sep 17 00:00:00 2001 From: tnguyenngocqa <51280278+tnguyenngocqa@users.noreply.github.com> Date: Sun, 15 Jan 2023 09:19:09 +0700 Subject: [PATCH 1/2] Lesson 6: Distinct https://app.codility.com/demo/results/training9CQXVB-6SV/ --- lessons/Distinct.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 lessons/Distinct.js 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; +} From 5778d3fdf7c08a325688d5d96e2121d4ca69f9cd Mon Sep 17 00:00:00 2001 From: tnguyenngocqa <51280278+tnguyenngocqa@users.noreply.github.com> Date: Sun, 15 Jan 2023 09:24:11 +0700 Subject: [PATCH 2/2] Readme - Lesson 6: Sorting - Distinct Update description - Lesson 6: Sorting - Distinct --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) 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/