Skip to content

Instantly share code, notes, and snippets.

@mishalrai
Last active March 29, 2018 18:04
Show Gist options
  • Save mishalrai/6b271050371b0d40a15f20aa099d751c to your computer and use it in GitHub Desktop.
Save mishalrai/6b271050371b0d40a15f20aa099d751c to your computer and use it in GitHub Desktop.
utilities fn in js
/******************************
* 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