We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f56f054 commit 591c9d5Copy full SHA for 591c9d5
02-basic-challenges-2/06-are-all-chars-unique/are-all-chars-unique.js
@@ -1,3 +1,28 @@
1
-function areAllCharactersUnique() {}
+//Solution 1
2
+function areAllCharactersUnique(str) {
3
+ let charCount = {};
4
+ for (let i = 0; i < str.length; i++) {
5
+ let char = str[i];
6
+ if (charCount[char]) {
7
+ return false;
8
+ }
9
+ charCount[char] = true;
10
11
+ return true;
12
+}
13
+
14
+//Solution 2
15
16
17
+ let charSet = new Set();
18
19
20
+ if (charSet.has(char)) {
21
22
23
+ charSet.add(char);
24
25
26
27
28
module.exports = areAllCharactersUnique;
0 commit comments