const deleted = [], updated = []
for (let oldidx = 0, newidx = 0; oldidx < current_data.length || newidx < new_data.length;) {
if (newidx >= new_data.length || current_data[oldidx]?.id < new_data[newidx].id) {
deleted.push(current_data[oldidx])
oldidx++
continue
}
if (oldidx >= current_data.length || current_data[oldidx].id > new_data[newidx]?.id || !lodash.isEqual(new_data[newidx], current_data[oldidx])) {
updated.push(new_data[newidx])
oldidx++
newidx++
continue
}
oldidx++
newidx++
}
const axios = require('axios').default
const axios = require('axios')
const _ = require('lodash')
const newArray = array_2
const oldArray = array_1
// возвращает новые и обновлённые данные
const changed = newArray.filter(newitem => {
const olditem = oldArray.find(o => o.id == newitem.id)
return !_.isEqual(newitem, olditem)
})
const deleted = oldArray.filter(olditem => {
const newitem = newArray.find(n => n.id == olditem.id)
return !_.isEqual(newitem, olditem)
}).filter(item => { // теперь нужно достать только удалённые данные, а обновлённые проигнорить.
const item = changed.find(cd => cd.name == item.name)
return !item
})
let radios = document.querySelectorAll('.order__form-step.active .radio__fake') // получили ВСЕ радиокнопки
if (...) {
radios.forEach(radio => radio.classList.add('error'))
} else {
radio.forEach(radio => {
radio.addEventListener('click', function (event) {
event.target.classList.remove(error);
});
})
}
<label>
<input type="checkbox">
</label>
<label>
<input type="checkbox">
</label>
<label>
<input type="checkbox">
</label>
<button disabled>Кнопка</button>
const inputs = [...document.querySelectorAll('input')]
const button = document.querySelector('button')
const onInput = () => {
if(document.querySelector('label.checked')) {
button.disabled = false
} else {
button.disabled = true
}
}
inputs.forEach(input => input.addEventListener('input', function(event) {
if (event.target.checked) {
event.target.closest('label').classList.add('checked')
} else {
event.target.closest('label').classList.remove('checked')
}
onInput()
}))