标签:
1.利用Object来做map查找array
//作业 var list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; var selectedList = [1, 5]; var ret = []; var hash = {}; function union( list, selectedList ){ var ret = []; list.forEach(function(item){ hash[item] = false; }); selectedList.forEach(function(item){ hash[ item ] = true; }) for(var key in hash){ if( !hash[key] ){ ret.push(key); } } return ret; } function selectorAll( list, selectedList ){ var ret = []; list.forEach( function( item ){ hash[itme] = false; }); selectedList.forEach(function( item ){ hash[ item ] = true; }) for(var key in hash){ if( hash[key] ){ ret.push(key); } } for(var key in hash){ if( !hash[key] ){ ret.push(key); } } return ret; }
标签:
原文地址:http://www.cnblogs.com/clearfix/p/4177098.html