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