I have arr with categories tree. Example: category yy is subcategory of ww and ww is subcategory of zz. I want to filter this array and get this output: ['aa_bb', 'aa_cc', 'zz_ww_yy']. So I don't want zz and zz_ww becouse i have this in zz_ww_yy. I think that I must use filter function and maybe some regexp? hmmm and maybe foreach? What you think?
var arr = ['aa_bb', 'aa_cc', 'aa', 'zz', 'zz_ww','zz_ww_yy'];
var filtered = arr.filter(function(a){
//???
})
console.log(filtered);