function min(obj) { var a = [obj[0]]; for (var i = 1; i < obj.length; i++) { for (var k = 0; k < a.length; k++) if (obj[i] < a[k]) break; a.splice(k, 0, obj[i]) } return a } alert(min([4, 8, 1, 12, -3, 1]));