I created a function that compares an array of letters to the alphabet, and returns the letters that are not in the original array.
While this works, it looks somewhat clumsy to me, but I don't know what I'm looking for to improve the code...Is there a way to make it more elegant? Perhaps getting rid of the notPresent
array somehow?
getLettersNotInContent(['z', 'a', 'p']);
function getLettersNotInContent(letters) {
// Filter dups if present
var uniques = [];
letters.filter(function(letter) {
if (uniques.indexOf(letter) === -1) {
uniques.push(letter);
}
});
// Filter and return the letters that are not present in the content
var alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
'p','q','r','s','t','u','v','w','x','y','z'];
var notPresent = [];
alphabet.filter(function(letter) {
if (uniques.indexOf(letter) === -1) notPresent.push(letter);
});
return notPresent;
}