Skip to content

Instantly share code, notes, and snippets.

@khalid32
Last active November 26, 2017 04:15
Show Gist options
  • Select an option

  • Save khalid32/1ad41c7f311c253dcb5990b664d0f252 to your computer and use it in GitHub Desktop.

Select an option

Save khalid32/1ad41c7f311c253dcb5990b664d0f252 to your computer and use it in GitHub Desktop.
place random unique IDs in array. If it exists, then it won't store into array.
let arrayOfID = [], temp;
storeBillIDinArray = (ID) => {
if(arrayOfID.length === 0){
arrayOfID.push(ID);
console.log(`Initial Array of ID: ${arrayOfID}`);
}else{
for(let i = 0; i < arrayOfID.length; i++){
if(arrayOfID[i] === ID){
console.log(`already exist!!`);
temp = null;
break;
}else{
console.log(`ID doesn't exist!!`);
temp = ID;
}
}
if(temp !== null){
arrayOfID.push(temp);
}
}
let sortedArray = arrayOfID.sort((a, b) => return a-b) ;
console.log(`Array of ID: ${sortedArray}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment