Douglas Crockford

Blog

Books

Videos

2020 Appearances

JavaScript

JSLint

JSON

Github

How JavaScript Works

About

Set Practice

Operate on arrays as though they are enumerable sets.

function objectify(array) {

Make an object in which the keys are the elements of an array.

    const objectification = Object.create(null);
    array.forEach(function (element) {
        objectification[element] = true;
    });
    return objectification;
}

export default Object.freeze({

    union: function (the_zeroth_set, the_wunth_set) {

Make the union of two arrays of strings.

        return Object.keys(
            Object.assign(
                objectify(the_zeroth_set),
                objectify(the_wunth_set)
            )
        );
    },

    intersection: function (the_zeroth_set, the_wunth_set) {

Make the intersection of two arrays of strings.

        const the_objectified_wunth = objectify(the_wunth_set);
        return the_zeroth_set.filter(
            function (element) {
                return the_objectified_wunth[element] !== undefined;
            }
        );
    },

    difference: function (the_zeroth_set, the_wunth_set) {

Make the difference of two arrays of strings.

        const the_objectified_wunth = objectify(the_wunth_set);
        return the_zeroth_set.filter(
            function (element) {
                return the_objectified_wunth[element] === undefined;
            }
        );
    }

});
jdb财神捕鱼单机版 在线广西快乐十分 甘肃快三计划免费版 手机赌博会坐牢吗 打牌赢真钱的软件有哪些 急速赛车技巧 体彩十一运夺金查询 上海银行股票行情 股票配资亏损案例 玩湖南快乐十分有什么好方法 重庆福彩幸运农场玩法