Last active
November 29, 2016 12:15
-
-
Save bjankord/33df380bdb135e8fa1899d323160b5d5 to your computer and use it in GitHub Desktop.
array filter and reject functionality
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
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); |
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
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