/ Published in: JavaScript
Expand |
Embed | Plain Text
var arr = [9, 9, 111, 2, 3, 4, 4, 5, 7]; var sorted_arr = arr.sort(); // You can define the comparing function here. JS default uses a crappy string compare. var results = []; for (var i = 0; i < arr.length - 1; i += 1) { if (sorted_arr[i + 1] == sorted_arr[i]) { results.push(sorted_arr[i]); } } alert(results);
You need to login to post a comment.
