s025236 2012-08-14 14:18:58

[JavaScript] テストも兼ねて、自分で書いたコードを張ってみる このエントリーをはてなブックマークに追加

投稿者からのアピールポイント

自分的にはおかしなコードは書いてないつもりでもきっと突込みがある・・・んじゃないかな

http://d.hatena.ne.jp/s025236/20111201/p1

if( typeof Array.prototype.map === 'undefined') Array.prototype.map = function($callback){
	var len	= this.length;
	var $_	= new Array(len);
	for(var i =0; i<len; i++){
		$_[i] = $callback.call(this,this[i],i);
	}
	return $_;
};
if( typeof Array.prototype.shuffle === 'undefined') Array.prototype.shuffle = function(){
	return this
		.map(function($_){return [Math.random(),$_]})
		.sort(function(a,b){return a[0] - b[0]})
		.map(function($_){return $_[1]})
	;
};

コメント(2)

#1 gocho 2012-08-15 03:21:50  

第三引数がない

#2 gocho 2012-08-15 03:24:23  

fisher-yatesの方が軽い