Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function verificar(arreglo){
- for(i = 0; i<arreglo.length-1; i++){
- if(arreglo[i]>arreglo[i+1]){
- return false
- }
- }
- return true
- }
- function ordenar(arreglo){
- while(!verificar(arreglo)){
- posA = Math.ceil(Math.random()*(arreglo.length-1));
- posB = Math.floor(Math.random()*(arreglo.length-1));
- aux = arreglo[posA];
- arreglo[posA] = arreglo[posB];
- arreglo[posB] = aux;
- }
- return arreglo;
- }
- arreglo = [4,5,1,2,3,9,8,10,-1];
- console.log(arreglo)
- console.log(ordenar(arreglo));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement