var a = [0,1,2,3,4,5,6,7,8,9]; a.sort(_=>Math.random() - 0.5); function f(a, k) { return a[a[a[a[a[a[a[a[a[a[a[k]]]]]]]]]]]+'-'+a.indexOf(k); } var i = 10; while(i--) console.log(f(a,i));