日期:2014-05-16 浏览次数:20575 次
<script tyep=text/javascript>
Array.prototype.map = function( fun ) {
var arr = [];
for (var i = 0; i < this.length; i ++) {
arr.push( fun.call(this[i], i) );
}
return arr
}
alert([0, 1, 2, 3].map(function() {
return this * 82 + (this > 1) * 8 + 10;
}))
</script>
------解决方案--------------------
当然是有规律的
function foo(n) {
var dict = [10, 12, 20, 12];
var width = 70;
if(n >= dict.length) n = dict.length - 1;
var t = width * n;
while(n >= 0) t += dict[n--];
return t;
}
document.write(foo(0)+'<br>');//10
document.write(foo(1)+'<br>');//92
document.write(foo(2)+'<br>');//182
document.write(foo(3)+'<br>');//264