Создание веб-приложения для калькулятора прямо сейчас, и я хочу сохранить отфильтрованный массив в новый массив «operatorNDInputList», чтобы он сохранил недублированные операторы в массиве.
Мне нужно, чтобы не проходить через массив до тех пор, пока не будет введено по крайней мере 2 входа, но затем продолжать работу даже после того, как массив переместил более двух входов?
Надеюсь, что это имеет смысл, возможно, вы сможете лучше понять, если не после просмотра кода:
'use strict';
const input = document.querySelector('#input'), // input/output button
numbers = document.querySelectorAll('.numbers div'), // number buttons
operators = document.querySelectorAll('.operators div'), // operator buttons
result = document.querySelector('#result'), // equal button
clear = document.querySelector('#clear'); // clear button
let numberInput = []
let operatorsInput = []
let operatorsNDInputList = []
document.querySelectorAll('.numbers div').forEach(buttonPress => {
buttonPress.addEventListener('click', (event) => {
numberInput.push(parseInt(event.target.textContent));
console.log(numberInput)
});
});
document.querySelectorAll('.operators div').forEach(buttonPress => {
buttonPress.addEventListener('click', (event) => {
operatorsInput.push(event.target.textContent);
console.log(operatorsInput)
});
});
operatorsInput.filter((item, index) => {
console.log(
item, index, operatorsInput.indexOf(item), operatorsInput.indexOf(item) === index,
);
return operatorsInput.indexOf(item) === index
});