From 7842632b4b8b22e0f8134251777cab16b61ecb22 Mon Sep 17 00:00:00 2001 From: Sirendra <51412551+Sirendra@users.noreply.github.com> Date: Tue, 26 Oct 2021 17:10:18 +0700 Subject: [PATCH] Update 10-sorted-union.js Reducing one iteration -> since we no operate on arr[0], I started for loop at index 1 instead of 0 --- .../10-sorted-union.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Javascript Algorithms And Data Structures Certification/Intermediate Algorithm Scripting/10-sorted-union.js b/Javascript Algorithms And Data Structures Certification/Intermediate Algorithm Scripting/10-sorted-union.js index 894fc02..5aac179 100644 --- a/Javascript Algorithms And Data Structures Certification/Intermediate Algorithm Scripting/10-sorted-union.js +++ b/Javascript Algorithms And Data Structures Certification/Intermediate Algorithm Scripting/10-sorted-union.js @@ -1,12 +1,13 @@ function uniteUnique(...arr) { - let result=[]; - arr.forEach(x=>{ - x.forEach(y=>{ - if(!result.includes(y)) // other way result.indexOf(y)==-1 - result.push(y); - }); - }); - return result; + for(let i=1;i