const comparators = [
[ 'city', (itemVal, filterVal) => itemVal === filterVal ],
[ 'title', (itemVal, filterVal) => itemVal.includes(filterVal) ],
[ 'type', (itemVal, filterVal) => itemVal.includes(filterVal) ],
];
const filteredArr = arr.filter(n => comparators.every(([ k, f ]) => f(n[k], filter[k])));
document.querySelectorAll('.group-options__item').forEach(n => {
const input = (n.closest('.group-options') ?? n).querySelector('[data-prop]');
if (input) {
input.checked = true;
}
});
function getStrings(str) {
const str1 = str.match(/\(.+?\)/g)?.find(n => /\d/.test(n)) ?? '';
return {
str1: str1.slice(1, -1),
str2: str.replace(str1, ''),
};
}
const select = document.querySelector('здесь селектор вашего select\'а');
const addValToText = option => addText(option, getVal(option));
const getVal = option => option.value;
// или
const getVal = option => option.getAttribute('value');
// или
const getVal = option => option.attributes.value.value;
const addText = (option, text) => option.text += text;
// или
const addText = (option, text) => option.textContent = option.textContent.concat(text);
// или
const addText = (option, text) => option.innerText = `${option.innerText}${text}`;
// или
const addText = (option, text) => option.append(text);
// или
const addText = (option, text) => option.insertAdjacentText('beforeend', text);
// или
const addText = (option, text) => option.appendChild(document.createTextNode(text));
// или
const addText = (option, text) => option.insertBefore(new Text(text), null);
Array.prototype.forEach.call(select, addValToText);
// или
select.querySelectorAll('option').forEach(addValToText);
// или
for (const n of select.options) {
addValToText(n);
}
// или
for (let i = 0; i < select.children.length; i++) {
addValToText(select.children[i]);
}
values: Array(height).fill(Array(width).fill(null))
values: Array.from({ length: height }, () => Array(width).fill(null))
const initialState = {
player: 'X',
cells: Array.from({ length: 3 }, () => Array(3).fill(null)),
};
const store = createStore((state = initialState, action) => {
switch (action.type) {
case 'MOVE':
return {
...state,
player: state.player === 'X' ? 'O' : 'X',
cells: state.cells.map((row, iRow) => iRow === action.location[0]
? row.map((cell, iCol) => iCol === action.location[1] ? state.player : cell)
: row
),
};
case 'RESET':
return initialState;
default:
return state;
}
});
const Board = connect(({ cells }) => ({ cells }))(({ cells }) => (
<div class="board">
{cells.map((row, iRow) =>
<div className="row">
{row.map((cell, iCol) =>
<Cell location={[ iRow, iCol ]} value={cell} />
)}
</div>
)}
</div>
));
const Cell = connect(null, (dispatch, { location }) => ({
onClick: () => dispatch({ type: 'MOVE', location }),
}))(({ value, onClick }) => (
<div className="cell">
<button onClick={onClick} disabled={value !== null}>
{value}
</button>
</div>
));
const Reset = connect(null, dispatch => ({
reset: () => dispatch({ type: 'RESET' }),
}))(({ reset }) => (
<button onClick={reset}>RESET</button>
));
const App = () => (
<Provider store={store}>
<Reset />
<Board />
</Provider>
);
v-scroll-text="{ selector: '.source-label', speed: 10 }"
scrollText(el, { value: { selector, speed } }) {
...
str.replace(/:$/, '')
// или
str.match(/[^:]+:[^:]+/)[0]
// или
str.match(/[^:]+/g).slice(0, 2).join`:`
// или
str.split(':', 2).join(':')
// или
str.slice(0, str.length - (str.slice(-1) === ':'))
$('.progress__item').each(function() {
const $this = $(this);
const $progressBar = $this.find('.progress__bar');
const $value = $this.find('.progress__value');
const value = $progressBar.data('progress-value');
$progressBar.width(`${value}%`);
$({ value: 0 }).animate({
value,
}, {
duration: 1000,
step: val => $value.text(`${val.toFixed(1)} %`),
});
});
пишу я на Vue, и к сожелению пока неочен хорошо знаком с Vue, поетому пока затрудняюсь подключить сей плагин