Test case details

Preparation Code

var arr = [], i, obj = {}; for(i = 0; i < 100; i += 1) { arr.push(i); obj[i] = i; } function getRandomIndex(obj) { var idx = Math.floor(Math.random()*99); if(false === obj.hasOwnProperty(idx)) { while (false === obj.hasOwnProperty(idx)) { idx = Math.floor(Math.random()*99); } } return idx; }

Test cases

Test #1

var idx = getRandomIndex(arr), a = arr[idx]; arr[idx] = Math.floor(Math.random()*99); arr.splice(idx,0); arr[length] = a;

Test #2

var idx = getRandomIndex(obj), a = obj[idx]; obj[idx] = Math.floor(Math.random()*99); delete obj[idx]; obj[idx] = a;