-
-
Save cferdinandi/e96773b49e9b07b8355a9ef84eabe883 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="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>dedupe()</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
</head> | |
<body> | |
<script> | |
/** | |
* Remove duplicate items from an array | |
* (c) Chris Ferdinandi, MIT License, https://gomakethings.com | |
* @param {Array} arr The array | |
* @return {Array} A new array with duplicates removed | |
*/ | |
function dedupe (arr) { | |
return Array.from(new Set(arr)); | |
} | |
let sandwiches = ['turkey', 'ham', 'turkey', 'tuna', 'pb&j', 'ham', 'turkey', 'tuna']; | |
// returns ["turkey","ham","tuna","pb&j"] | |
let deduped = dedupe(sandwiches); | |
console.log(deduped); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment