Last active
November 26, 2017 04:15
-
-
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.
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
| 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