HTMLで重複行チェックページ

f:id:peroon:20121101050400p:plain

<head>
<meta charset="UTF-8">
<script  type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
 
<script type="text/javascript">
 
function check_duplicate(){
 
  var text = $("#checkarea").val();
 
  //remove tail-line-break
  text=text.replace(/\n+$/g,'');
 
  var arr = text.split('\n');
  var is_dup = is_duplicate(arr);
  
  if(is_dup){
    alert('duplicated!');
  }else{
    alert('not duplicated!');
  }
}
 
function is_duplicate(arr){
  var len = arr.length;
 
  var hash = {};
  for(var i in arr){
    var val = arr[i];
    hash[val] = 'dummy';
  }
  
  var hash_len = 0;
  for(key in hash){
    hash_len++;
  }
 
  if(len==hash_len){return false;}
  else{return true;}
}
 
</script> 
</head>
 
<h1>重複チェック</h1>
<h1>Check for duplicate</h1>
 
<input type="button" value="Check!" onclick="check_duplicate()"><br>
<textarea id="checkarea" cols="100" rows="100"></textarea>