Last active
March 29, 2018 18:04
-
-
Save mishalrai/6b271050371b0d40a15f20aa099d751c to your computer and use it in GitHub Desktop.
utilities fn in js
This file contains 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
/****************************** | |
* Arry unique | |
****************************** */ | |
function arrUnique(arr){ | |
let len = arr.length; | |
let newArr = []; | |
for( let i=0; i < len; i++ ){ | |
if( newArr.indexOf(arr[i]) === -1){ | |
newArr.push(arr[i]); | |
} | |
} | |
return newArr; | |
} | |
function arrUnique(arr){ | |
let len = arr.length, | |
temp, | |
newArr=[]; | |
arr.sort(); | |
for( i=0; i< len; i++){ | |
if( temp !== arr[i]){ | |
newArr.push(arr[i]); | |
temp = arr[i]; | |
} | |
} | |
return newArr; | |
} | |
function arrUnique(arr){ | |
let newArr = new Set(arr); // set is es6 function which return unique set | |
return [... newArr]; // it's convert set to array | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment