From 9f90d6557ddb300d3d2982e9a4fa58cb03e72346 Mon Sep 17 00:00:00 2001 From: qasimala <58895064+qasimala@users.noreply.github.com> Date: Wed, 27 Apr 2022 00:13:42 +0200 Subject: [PATCH 1/3] Added two additional methods - 217 Contains Duplicates --- javascript/217-Contains-Duplicate.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/javascript/217-Contains-Duplicate.js b/javascript/217-Contains-Duplicate.js index 3c96a1b20..f213a4f0f 100644 --- a/javascript/217-Contains-Duplicate.js +++ b/javascript/217-Contains-Duplicate.js @@ -2,6 +2,8 @@ * @param {number[]} nums * @return {boolean} */ + +//First method using Map() (exit early if true) var containsDuplicate = function(nums) { let map = {}; @@ -14,3 +16,23 @@ var containsDuplicate = function(nums) { } return false; }; + + +/* +//Second method using Map() (Has to map entire array but code is more readable) + +const containsDuplicate = function(nums) { + //create a new hashmap with all the items in the array. Any duplicates will be removed. + let totalWithoutDuplicates = new Map(nums.map((i) => [i])); + + //check if the size of the initial array is larger than the new hashmap. + return totalWithoutDuplicates.size !== nums.length; +}; + +//Third method using Set() (Fastest runtime at 91.95% and very readable code) + +var containsDuplicate = function(nums) { + //Pass the array into a Set() (which removes duplicates) and then compare its size to the original array. + return new Set(nums).size !== nums.length; +} +*/ From fb1a152d36f5767cfae94b7a09409585a1067a5a Mon Sep 17 00:00:00 2001 From: Mitchell Irvin <16233245+mitchellirvin@users.noreply.github.com> Date: Mon, 11 Jul 2022 09:44:52 -0400 Subject: [PATCH 2/3] Update 217-Contains-Duplicate.js --- javascript/217-Contains-Duplicate.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/javascript/217-Contains-Duplicate.js b/javascript/217-Contains-Duplicate.js index f213a4f0f..49f8161e9 100644 --- a/javascript/217-Contains-Duplicate.js +++ b/javascript/217-Contains-Duplicate.js @@ -17,10 +17,7 @@ var containsDuplicate = function(nums) { return false; }; - -/* //Second method using Map() (Has to map entire array but code is more readable) - const containsDuplicate = function(nums) { //create a new hashmap with all the items in the array. Any duplicates will be removed. let totalWithoutDuplicates = new Map(nums.map((i) => [i])); @@ -30,9 +27,7 @@ const containsDuplicate = function(nums) { }; //Third method using Set() (Fastest runtime at 91.95% and very readable code) - var containsDuplicate = function(nums) { //Pass the array into a Set() (which removes duplicates) and then compare its size to the original array. return new Set(nums).size !== nums.length; } -*/ From 45a6b659c1052e0c43570a94e7b21737986ec1fc Mon Sep 17 00:00:00 2001 From: Mitchell Irvin <16233245+mitchellirvin@users.noreply.github.com> Date: Mon, 11 Jul 2022 09:46:31 -0400 Subject: [PATCH 3/3] Update 217-Contains-Duplicate.js --- javascript/217-Contains-Duplicate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/217-Contains-Duplicate.js b/javascript/217-Contains-Duplicate.js index 17c5449d0..e9912889e 100644 --- a/javascript/217-Contains-Duplicate.js +++ b/javascript/217-Contains-Duplicate.js @@ -18,7 +18,7 @@ var containsDuplicate = function(nums) { //Second method using Map() (Has to map entire array but code is more readable) var containsDuplicate = function(nums) { //create a new hashmap with all the items in the array. Any duplicates will be removed. - let totalWithoutDuplicates = new Map(nums.map((i) => [i])); + const totalWithoutDuplicates = new Map(nums.map((i) => [i])); //check if the size of the initial array is larger than the new hashmap. return totalWithoutDuplicates.size !== nums.length; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy