const [ zero, one, two, three, four, five, six, seven, eight, nine ] = Array.from(
{ length: 10 },
(_, i) => f => f instanceof Function ? f(i) : i
// или
// (_, i) => f => f?.(i) ?? i
);
const plus = a => b => b + a;
const minus = a => b => b - a;
const times = a => b => b * a;
const dividedBy = a => b => b / a | 0;
const sortDigits = num => +[...`${num}`].sort((a, b) => b - a).join('');
const sortDigits = num => ''.concat.apply('', num.toString().split('').sort().reverse()) - 0;
const sortDigits = num => Number(Array
.from('' + num)
.reduce((acc, n) => (acc[n]++, acc), Array(10).fill(0))
.reduceRight((acc, n, i) => acc + String(i).repeat(n), '')
);
const sortDigits = num => Array
.prototype
.reduce
.call(String(num), (acc, n) => ((acc[9 - n] ??= []).push(n | 0), acc), [])
.flat()
.reduce((acc, n) => acc * 10 + n, 0);
from collections import Counter
item = Counter(arr).most_common(1)[0][0]
computed: {
columns() {
return Object.keys(this.fedresurs.find(n => n.items.length)?.items[0] ?? {});
},
},
<table v-for="messages in fedresurs">
<caption>{{ messages.title }}</caption>
<thead>
<tr>
<th v-for="column in columns">{{ column }}</th>
</tr>
</thead>
<tbody>
<tr v-for="item in messages.items">
<td v-for="column in columns">{{ item[column] }}</td>
</tr>
</tbody>
</table>
products.insert(contentsOf: drinks, at: 0)
.for n in drinks.reversed() {
products.insert(n, at: 0)
}
// или
for i in (0 ..< drinks.count) {
products.insert(drinks[i], at: i)
}
Использую yandex-map@beta
пытаюсь изменить параметр zoom в YandexMap, но не работает, и что-то мне подсказывает, что не всё так просто
setup() {
...
let map = null;
return {
...
onCreate: e => map = e,
updateZoom: z => map.setZoom(Math.max(1, Math.min(19, map.getZoom() + z))),
};
},
<yandex-map
...
@created="onCreate"
/>
...
<button @click="updateZoom(+1)">+</button>
<button @click="updateZoom(-1)">-</button>
срабатывает дважды, а в последующие разы увеличивается в разы
useEffect(() => { window.addEventListener('keydown', onKeyPress); }, [focus])
useEffect(() => {
const onKeyDown = ({ keyCode }) => {
if (keyCode === 39) {
setFocus(focus => focus + 1);
}
};
window.addEventListener('keydown', onKeyDown);
return () => window.removeEventListener('keydown', onKeyDown);
}, []);
state = {
phones: [
{ id: 1, title: '', number: '' },
],
}
onChange = ({ target: { value, name, dataset: { index } } }) => {
this.setState(({ phones }) => ({
phones: phones.map((n, i) => +index === i
? { ...n, [name]: value }
: n
),
}));
}
addPhone = () => {
this.setState(({ phones }) => ({
phones: [
...phones,
{
id: 1 + Math.max(...phones.map(n => n.id)),
title: '',
number: '',
},
],
}));
}
delPhone = ({ target: { dataset: { index } } }) => {
this.setState(({ phones }) => ({
phones: phones.filter((n, i) => i !== +index),
}));
}
render() {
return (
<div>
{this.state.phones.map((n, i) => (
<div key={n.id}>
<input name="title" data-index={i} value={n.title} onChange={this.onChange} />
<input name="number" data-index={i} value={n.number} onChange={this.onChange} />
{i ? <button data-index={i} onClick={this.delPhone}>x</button> : null}
</div>
))}
<button onClick={this.addPhone}>Add</button>
</div>
);
}
data: () => ({
currencies: [
{ title: 'рубль', rate: 1, val: 0 },
{ title: 'доллар', rate: 62.65, val: 0 },
{ title: 'евро', rate: 60.90, val: 0 },
],
}),
methods: {
onInput({ rate, val }) {
this.currencies.forEach(n => n.val = val * rate / n.rate);
},
},
<div v-for="n in currencies">
<input
v-model.number="n.val"
@input="onInput(n)"
type="number"
min="0"
>
{{ n.title }}
</div>
Что я делаю не так
как решить проблему?
{ LikeIcon }
---> <LikeIcon />
. const statsMeta = [
{ title: 'отредактированные', count: item => +item.edited },
{ title: 'неотредактированные', count: item => +!item.edited },
{ title: 'всего', count: () => 1 },
];
const statsData = allMessages.reduce((acc, n) => (
statsMeta.forEach((m, i) => acc[i] += m.count(n)),
acc
), Array(statsMeta.length).fill(0));
console.log(statsMeta.map((n, i) => `${n.title}: ${statsData[i]}`).join('\n'));
const classPrefix = 'modal--';
Array.from(el.classList).forEach(n => el.classList.toggle(n, !!n.indexOf(classPrefix)));
el.classList.remove(...[...el.classList].filter(n => n.startsWith(classPrefix)));
for (let i = el.classList.length; i--;) {
if (el.classList[i].search(classPrefix) === 0) {
el.classList.remove(el.classList[i]);
}
}
el.classList.value = el.classList.value
.split(' ')
.filter(RegExp.prototype.test.bind(RegExp(`^(?!${classPrefix})`)))
.join(' ');
el.className = el.className.replace(RegExp(`(^| )${classPrefix}\\S*`, 'g'), '').trim();
const result = arr2.map(function(n) {
return Object.fromEntries(this.map(m => [ m[1], n[m[0]] ]));
}, arr1.flatMap(Object.entries));
const keys = Object.entries(Object.assign({}, ...arr1));
const result = arr2.map(n => keys.reduce((acc, m) => (acc[m[1]] = n[m[0]], acc), {}));
const [ todos, setTodos ] = useState(() => {
let todos = null;
try {
todos = JSON.parse(localStorage.getItem('todos'));
} catch (e) {};
return Array.isArray(todos) ? todos : [];
});
setTodos([ ...todos, { id: Date.now(), complete: false, title: value, }, ]); localStorage.setItem("todos", JSON.stringify(todos));
useEffect(() => {
localStorage.setItem('todos', JSON.stringify(todos));
}, [ todos ]);
const xxx = str => Array
.from(str, (n, i) => n.toUpperCase() + n.toLowerCase().repeat(i))
.join('-');
const xxx = str => str
.toUpperCase()
.split('')
.reduce((acc, n, i) => `${acc}${i ? '-' : ''}${n}${Array(-~i).join(n.toLowerCase())}`, '');
const xxx = str => str
.toUpperCase()
.replace(/(?<=.)./g, (m, i) => '-'.concat(m, ...Array(i).fill(m.toLowerCase())));
data: () => ({
filterColumns: [
[ 'name', 'имя', 'string' ],
[ 'count', 'количество', 'number' ],
[ 'distance', 'расстояние', 'number' ],
],
operations: [
[ 'equal', 'равно' ],
[ 'contains', 'содержит' ],
[ 'greater', 'больше' ],
[ 'less', 'меньше' ],
],
...
data: () => ({
types: {
string: {
equal: (a, b) => a.toLowerCase() === b,
contains: (a, b) => a.toLowerCase().includes(b),
greater: (a, b) => a.toLowerCase() > b,
less: (a, b) => a.toLowerCase() < b,
},
number: {
equal: (a, b) => a === +b,
contains: (a, b) => `${a}`.includes(b),
greater: (a, b) => a > +b,
less: (a, b) => a < +b,
},
},
...
<select v-model="column">
<option v-for="n in filterColumns" :value="n[0]">{{ n[1] }}</option>
</select>
<select v-model="operation">
<option v-for="n in operations" :value="n[0]">{{ n[1] }}</option>
</select>
computed: {
filteredItems() {
const { items, column } = this;
const type = this.filterColumns.find(n => n[0] === column)?.[2];
const filterFn = this.types[type]?.[this.operation];
const filterVal = this.filterVal.toLowerCase();
return filterFn && filterVal
? items.filter(n => filterFn(n[column], filterVal))
: items;
},
...