Skip to content

Instantly share code, notes, and snippets.

@bjankord
Last active November 29, 2016 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjankord/33df380bdb135e8fa1899d323160b5d5 to your computer and use it in GitHub Desktop.
Save bjankord/33df380bdb135e8fa1899d323160b5d5 to your computer and use it in GitHub Desktop.
array filter and reject functionality
const list = ['apple', 'orange', 'bananna'];
function isThemableIcon(value) {
return ['orange', 'bananna'].indexOf(value) >= 0;
}
const themableIcons = list.filter(isThemableIcon);
const staticIcons = list.filter(x => !isThemableIcon(x));
console.log(themableIcons);
console.log(staticIcons);
var icons = [ { iconName: 'abnormal',
svg: 'src/icons/0125_abnormal_i_lightDiamond.svg' },
{ iconName: 'add', svg: 'src/icons/0001_plus_a.svg' },
{ iconName: 'addPerson',
svg: 'src/icons/0113_plusPerson_a.svg' },
{ iconName: 'alert',
svg: 'src/icons/0037_exclamation_i_heavyTriangle.svg' },
{ iconName: 'analytics',
svg: 'src/icons/0070_dottedLine_a.svg' },
{ iconName: 'announcement',
svg: 'src/icons/0071_megaphone_a.svg' }
];
var staticIcons = ["abnormal"];
function isStaticIcon(item) {
return staticIcons.indexOf(item.iconName) > -1;
}
var staticIconsList = icons.filter(isStaticIcon);
var themableIconsList = icons.filter(x => !isStaticIcon(x));
console.log(staticIconsList);
console.log(themableIconsList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment