Groovy web console

subscribe to the feed Subscribe
to this
site

Bubble N

Published 4 years ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
a=[5,1,4, 2, 8]
m={l,n->s={x,y->t=l[x];l[x]=l[y];l[y]=t};((l.size()-2)..2).each{i->(0..i).each{if(l[it]>l[it+1] && n){s(it,it+1)};n--}};l}
m(a,5)