From e991e7e134ab51e8df7d33708b831570a3a02778 Mon Sep 17 00:00:00 2001 From: Nairi Haroutiounian Date: Wed, 26 Sep 2018 10:07:37 +0400 Subject: [PATCH] Improve allUniqueChars logic As in book written, if string length exceeds the number of unique characters in the alphabet we can return false. --- chapter01/1.1 - Is Unique/isUnique.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chapter01/1.1 - Is Unique/isUnique.js b/chapter01/1.1 - Is Unique/isUnique.js index 136496c..967cf6b 100644 --- a/chapter01/1.1 - Is Unique/isUnique.js +++ b/chapter01/1.1 - Is Unique/isUnique.js @@ -1,4 +1,5 @@ var allUniqueChars = function(string) { + if (string.length > 128) returne false; // O(n^2) approach, no additional data structures used // for each character, check remaining characters for duplicates @@ -13,4 +14,4 @@ var allUniqueChars = function(string) { }; /* TESTS */ -// log some tests here \ No newline at end of file +// log some tests here