exports.findOrCreate = function findOrCreate(userID, provider){
return new Promise(function(resolve, reject) {
client.getAsync('accounts:' + provider + ':' + userID).then((accountID) => {
if (accountID !== null) {
client.hgetallAsync('account:' + accountID).then(resolve, reject);
} else {
reject();
}
}, reject);
});
};
if (![ 'search', 'search_input', 'cancel_btn' ].includes(target.className)) {
const t = target.className;
if (t !== 'search' && t !== 'search_input' && t !== 'cancel_btn') {
if (!target.matches('.search, .search_input, .cancel_btn')) {
<div class="block">hello, world!!</div>
<div class="block">fuck the world</div>
<div class="block">fuck everything</div>
.block {
display: inline-block;
width: 500px;
height: 150px;
padding: 20px;
background: red;
color: white;
}
const $blocks = $('.block').hide();
let i = -1;
(function showNext() {
$blocks
.eq(i = (i + 1) % $blocks.length)
.dequeue()
.fadeIn(1000)
.delay(500)
.fadeOut(1000)
.queue(showNext);
})();
Math.max(...list)
Работает все ок...
function max(data, key = n => n) {
const getVal = key instanceof Function ? key : n => n[key];
let result = void 0;
for (const n of data) {
const val = getVal(n);
result = result && result[1] > val ? result : [ n, val ];
}
return result && result[0];
}
max([ 12, 9, -47, 83, 22 ]) // 83
max('240815', Number) // '8'
max(document.images, 'width') // не знаю, что выдаст вам, сами посмотрите
max((function*() {
yield 'aaa';
yield 'b';
yield 'cccc';
yield 'ddd';
})(), n => n.length) // 'cccc'
|о|д|и|н|
|е|т|ы|д|
|ч|е|р|в|
|и|р|т|а|
function makeTable(data) {
data = data.join('').split('');
let width = Math.sqrt(data.length) | 0;
let height = (data.length / width) | 0;
while (width * height !== data.length) {
width--;
height = (data.length / width) | 0;
}
const position = [ 0, 0 ];
const directions = [
[ 1, 0 ],
[ 0, 1 ],
[ -1, 0 ],
[ 0, -1 ],
];
let direction = 0;
const result = Array.from({ length: height }, n => Array(width).fill(null));
for (const n of data) {
result[position[1]][position[0]] = n;
if (null !== (result[position[1] + directions[direction][1]] || {})[position[0] + directions[direction][0]]) {
direction = (direction + 1) % directions.length;
}
position[0] += directions[direction][0];
position[1] += directions[direction][1];
}
return result.map(n => n.join(' ')).join('\n');
}
console.log(makeTable([ 'раз', 'два', 'три' ])); /*
р а з
р и д
т а в
*/
console.log(makeTable([ 'один', 'два', 'три', 'четыре' ])); /*
о д и н
е т ы д
ч е р в
и р т а
*/
console.log(makeTable([ 'hello', ',', ' ', 'world', '!!' ])); /*
h e
! l
! l
d o
l ,
r
o w
*/
SELECT `year`, COUNT(*)
FROM (
SELECT YEAR(p.age) AS `year`, p.id
FROM apointments a
JOIN pations p ON p.id = a.idp
GROUP BY p.id
) t
GROUP BY `year`
const elems = document.querySelectorAll('div');
function handler() {
alert(123);
elems.forEach(n => n.removeEventListener('click', handler));
}
elems.forEach(n => n.addEventListener('click', handler));
const elems = [...document.querySelectorAll('div')];
document.addEventListener('click', function handler(e) {
if (elems.some(n => n.contains(e.target))) {
alert(123);
document.removeEventListener('click', handler);
}
});
return *head->...
должно быть return head->...
. SELECT *
FROM table
WHERE (SELECT array_agg((t->>'category_id')::INT) FROM jsonb_array_elements(data->'items') AS t) && ARRAY[1,3,5]
SELECT *
FROM table
WHERE ARRAY(SELECT t.category_id FROM jsonb_to_recordset(data->'items') AS t(category_id INT)) && ARRAY[1,3,5]
options: {
scales: {
xAxes: [ {
ticks: {
fontFamily: 'Impact, Charcoal, sans-serif'
}
} ]
}
}
const selector = '[id^="oOR"]';
const clickCount = 100;
$(selector).slice(0, clickCount).click();
// или
[...document.querySelectorAll(selector)].slice(0, clickCount).forEach(n => n.click());
из-за "одновременного" клика все виснет
Может подскажете конструкцию с .delay() (или чем то аналогичным)
function chunkedAndDelayed(data, delay, chunkSize, onChunk) {
const getChunk = (data.slice || Array.prototype.slice).bind(data);
(function nextChunk(i) {
if (i < data.length) {
onChunk(getChunk(i, i + chunkSize));
setTimeout(nextChunk, delay, i + chunkSize);
}
})(0);
}
const delay = 500;
const clickChunkSize = 5;
chunkedAndDelayed(
$(`${selector}:lt(${clickCount})`),
delay,
clickChunkSize,
$elems => $elems.click()
);
// или
chunkedAndDelayed(
Array.prototype.slice.call(document.querySelectorAll(selector), 0, clickCount),
delay,
clickChunkSize,
elems => elems.forEach(n => n.click())
);