+str.replace(/[^\d.]/g, '')
parseFloat(str.match(/[\d.]/g).join(''))
arr.reduceRight((_, n, i, a) => indexes.includes(i) && a.splice(i, 1), null);
// или
[...indexes].sort((a, b) => b - a).forEach(i => arr.splice(i, 1));
// или
arr.splice(0, arr.length, ...arr.filter((n, i) => indexes.indexOf(i) === -1));
const newArr = arr.filter(((indexes, n, i) => !indexes.has(i)).bind(null, new Set(indexes)));
<Transactions />
class="filter-menu"
{transaction}
<div>{transaction.type}</div>
<div>{transaction.date}</div>
useEffect(() => {
const onKeypress = e => console.log(e);
document.addEventListener('keypress', onKeypress);
return () => {
document.removeEventListener('keypress', onKeypress);
};
}, []);
const Comments = ({ items }) =>
Array.isArray(items) && items.length
? <React.Fragment>{items.map(n =>
<div className="comment" key={n.id}>
<h3>{n.name}</h3>
<div>{n.body}</div>
<Comments items={n.reply} />
</div>)}
</React.Fragment>
: null;
async function request(data) {
let result = data;
do {
result = await запрос(result);
} while (result не тот, который нужен);
return result;
}
function requestRecursive(data) {
return запрос(data).then(result => {
return result тот, который нужен
? result
: requestRecursive(result);
});
}
const values = Object.values(obj);
const count = values.flat().length;
// или
const count = [].concat(...values).length;
// или
const count = values.reduce((acc, n) => acc + n.length, 0);
// или
const count = eval(values.map(n => n.length).join('+')) || 0;
a = [ 1, 2, 3 ];
b = [ 4, 5, 6 ];
c = a;
// здесь должен быть какой-то код
console.log(a); // [ 4, 5, 6 ]
console.log(b); // [ 1, 2, 3 ]
console.log(a === c); // true
b.splice(0, b.length, ...a.splice(0, a.length, ...b));
const index = myCollection.indexOf(e.get('target'));
alert(myCoords[index].text);
data: () => ({
image: 0,
images: [ 'раз картинка', 'два картинка', 'три картинка' ],
}),
<button v-for="(n, i) in images" @click="image = i">
Показать картинку #{{ i }}
</button>
<transition name="image" mode="out-in">
<img :key="image" :src="images[image]">
</transition>
.image-enter-active,
.image-leave-active {
transition: opacity .3s;
}
.image-enter,
.image-leave-to {
opacity: 0;
}
const filteredProducts = [
[ true, n => n.type === 'Bras' ],
[ true, n => n.price <= tempPrice ],
[ color !== 'all', n => n.color === color ],
[ cup, n => n.cup.includes(cup) ],
[ shipping, n => n.freeShipping === true ],
[ search, n => n.title.toLowerCase().startsWith(search.toLowerCase()) ],
].reduce((products, [ active, fn ]) => {
return active
? products.filter(fn)
: products;
}, storeProducts);
this.setState({ filteredProducts });
Вариант добавить в лоб, как я сделал это выше class='test', не сработал.
Этот класс применился к input. А мне нужно применить класс к самому select, который появляется перед закрывающим тегом body.
Array.from(new Set(arr.flat()))
// или, без создания промежуточного массива
[...arr.reduce((acc, n) => (n.forEach(m => acc.add(m)), acc), new Set)]
Object.keys([].concat(...arr).reduce((acc, n) => (acc[n] = 1, acc), {}))
// или
Array.prototype.concat.apply([], arr).filter((n, i, a) => i === a.indexOf(n))
// или
`${arr}`.split(',').reduce((acc, n) => (acc.includes(n) || acc.push(n), acc), [])
// или
String(arr).match(/\w/g).sort().filter((n, i, a) => n !== a[i - 1])
// или
arr.toString().match(/(\w)(?!.*\1)/g) || []