美文网首页
数组字典

数组字典

作者: 我叫琪琪呀 | 来源:发表于2021-07-27 18:08 被阅读0次

例如1234   2345  得234

数组求差集

    const deleteRepeat = (beforeCity, newCity) => {

        var arrBeforeCity = [];

        var arrNewCity = [];

        beforeCity.map((v, i) => {

            arrBeforeCity.push(v.cityCode);

        });

        newCity.map((v, i) => {

            arrNewCity.push(v.cityCode);

        });

        var allDeletecity = deleteCity(arrBeforeCity, arrNewCity);

        return allDeletecity;

    };

例如1234   2345  得1

   数组压成字典

    const arrChangeDic = (arr1, arr2) => {

        var map1 = new Map();

        arr1.map((item, i) => {

            map1.set(item.cityCode, item);

        });

        arr2.map((item, i) => {

            if (map1.has(item.cityCode)) {

                map1.delete(item.cityCode);

            }

        });

        var cityCode = [];

        //取出citycode

        for (let key of map1.keys()) {

            cityCode.push(key);

        }

        return cityCode;

    };

相关文章

网友评论

      本文标题:数组字典

      本文链接:https://www.haomeiwen.com/subject/npbomltx.html