This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample array | |
var collection = [1, 3, 7, 9, 0, 2, 5, 3, 8, 10, 2, 11, 7, 1, 7, 4, 6, 8, 1, 0]; | |
/* O(n²) complexity on worst case scenarios, but O(n) on best scenarios */ | |
/* 2. Resize the array with two nested loops, but it goes one forward comparing and another backwards removing | |
The result is a faster interaction because we are removing duplicated ahead before Forward hits it */ | |
function BackForwardUnique(arr){ | |
for(var forward = 0; forward < arr.length; forward++){ | |
for (var backward = arr.length - 1; backward > forward; backward--){ |