- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbubbleSort.js
More file actions
Latest commit
27 lines (20 loc) · 599 Bytes
/
Copy pathbubbleSort.js
File metadata and controls
27 lines (20 loc) · 599 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
letbubbleSort=(myArray,cb)=>{
letiterativeRange=myArray.length-1;
while(iterativeRange--){
for(letindex=0;index<myArray.length-1;index++){
letfirstValue=myArray[index];
letsecondValue=myArray[index+1];
if(firstValue>secondValue){
myArray[index]=secondValue;
myArray[index+1]=firstValue;
}
}
}
returncb(null,myArray);
};
bubbleSort([5,3,8,2,1,4],(err,myArray)=>{
if(err){
}else{
console.log(myArray);
}
});