Показать сообщение отдельно
  #2 (permalink)  
Старый 13.12.2018, 12:47
Профессор
Отправить личное сообщение для Nexus Посмотреть профиль Найти все сообщения от Nexus
 
Регистрация: 04.12.2012
Сообщений: 3,733

const push = (function() {
    const container = [];
    const alreadyInContainerIndex = {};

    const checkItem = function(item) {
        return item === null || !alreadyInContainerIndex[item.id];
    };

    return function(data) {
        if (!checkItem(data))
            return;

        const index = container.push(data) - 1;
        if (data)
            alreadyInContainerIndex[data.id] = index;
    }
})();
Ответить с цитированием