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;
const nextY = position[1] + directions[direction][1];
const nextX = position[0] + directions[direction][0];
if (null !== (result[nextY] || {})[nextX]) {
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->...
.