Created
January 15, 2016 09:57
-
-
Save sylph01/f31d27ec184572d5b6bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Sample</title> | |
<script type="text/javascript" src="jquery-1.12.0.min.js"></script> | |
<script type="text/javascript"> | |
$(function(){ | |
$('#button').click(function(){ | |
var list1 = $('#list1').val(); | |
var list1_arr = list1.split('\n'); | |
var arr_length = list1_arr.length; | |
var array_info = "Array length: " + arr_length + "<br /><br />"; | |
var non_unique_elements = list1_arr.filter(function (x, i, self) { | |
return self.indexOf(x) === i && i !== self.lastIndexOf(x); | |
}); | |
var unique_only = list1_arr.filter(function (x, i, self) { | |
return self.indexOf(x) === i | |
}); | |
array_info += "Non-unique Elements (" + non_unique_elements.length + "): <br />"; | |
for (var i = 0; i < non_unique_elements.length; i++) { | |
array_info += non_unique_elements[i] + "<br />"; | |
} | |
$('#list3').val(unique_only.join('\n')); | |
$('#array_info').html(array_info); | |
}); | |
}); | |
</script> | |
<style type="text/css"> | |
.container { | |
float: left; | |
width: 280px; | |
margin: 0; | |
padding: 10px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<textarea id="list1" rows="20" cols="25"></textarea><br /> | |
<input type="button" value="Submit" id="button" /> | |
</div> | |
<div class="container"> | |
<textarea id="list3" rows="20" cols="25"></textarea> | |
</div> | |
<div class="container"> | |
<div id="array_info"></div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment