Skip to content

Instantly share code, notes, and snippets.

@arup-b
Last active September 16, 2016 07:06
Show Gist options
  • Save arup-b/120a896a317315496e9ff1b1bfcbd6d4 to your computer and use it in GitHub Desktop.
Save arup-b/120a896a317315496e9ff1b1bfcbd6d4 to your computer and use it in GitHub Desktop.
Function to check if an Array has duplicate elements
var ar = ['https://scontent.cdninstagram.com/t50.2886-16/13351747_1548398895467100_1473273865_n.mp4',
'https://scontent.cdninstagram.com/t50.2886-16/13427635_553906271448787_1921670084_s.mp4',
'http://planetairsport.digitalsign.social/files/ae5fbf6e17d3f99a65742fff88abe1fd.jpg',
'http://planetairsport.digitalsign.social/files/2242d160aec87a46a7c9a12395b02c80.jpg',
'http://planetairsport.digitalsign.social/files/09e72e18197a3c19eb48e364e1486b50.jpg',
'https://scontent.cdninstagram.com/t50.2886-16/13647809_902603383185427_359341575_n.mp4',
'http://planetairsport.digitalsign.social/files/bfde5b157d067023e5216ea2316c4cb7.jpg',
'https://scontent.cdninstagram.com/t50.2886-16/13728792_1738082423127752_382512439_n.mp4',
'http://planetairsport.digitalsign.social/files/d6ed32c3784bd6883db17c6282203727.jpg',
'http://planetairsport.digitalsign.social/files/c82e093fcab76c4105d74221ed1fa78e.jpg',
'https://scontent.cdninstagram.com/t50.2886-16/13544976_1224376924261356_322535264_n.mp4',
'http://planetairsport.digitalsign.social/files/050e252a67ef3ab3c7c059b92431b1c7.jpg',
'http://planetairsport.digitalsign.social/files/f6b4133a5c6753c57f178c174fcb97ed.jpg',
'http://planetairsport.digitalsign.social/files/ce0b7e3a872ade6faf0f41f07f269ea4.jpg',
'https://scontent.cdninstagram.com/t50.2886-16/13960135_289908344698988_1464142592_n.mp4',
'https://scontent.cdninstagram.com/t50.2886-16/14033392_935535729926632_291621110_n.mp4',
'http://planetairsport.digitalsign.social/files/562a531f931208ae5815e8c5d10fed87.jpg',
'http://planetairsport.digitalsign.social/files/3e9b4bf38365bead9674b6b4b506c876.jpg'];
function hasDuplicates (arr:Array){
var x:uint;
var y:uint;
//
for (x = 0; x < arr.length; x++) {
//
for (y = x + 1; y < arr.length; y++) {
//
if (arr[x] === arr[y]) {
return true;
}
}
}
return false;
}
console.log(hasDuplicates(ar));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment