const propsCount = 3;.const newObj = Object.fromEntries(Object
.entries(obj)
.sort((a, b) => a[1] - b[1])
.slice(-propsCount)
);Object
.entries(obj)
.sort((a, b) => b[1] - a[1])
.slice(propsCount)
.forEach(n => delete obj[n[0]]);
const newUrl = url.match(/.+\//)[0];
// или
const newUrl = url.replace(/[^\/]+$/, '');
// или
const newUrl = url.slice(0, url.lastIndexOf('/') + 1);
// или
const newUrl = url.split(/(\/)/).slice(0, -1).join('');preg_match('/.+\//', $url, $match);
$newUrl = $match[0];
// или
$newUrl = preg_replace('/[^\/]+$/', '', $url);
// или
$newUrl = substr($url, 0, strrpos($url, '/') + 1);
// или
$newUrl = implode('', array_slice(preg_split('/(\/)/', $url, 0, PREG_SPLIT_DELIM_CAPTURE), 0, -1));
const sum = arr.reduceRight((acc, n) => n && acc + n, 0);let sum = 0;
for (let i = 0; arr[i]; sum += arr[i++]) ;let sum = 0;
for (const n of arr) {
if (!n) {
break;
}
sum += n;
}const sum = (function sum(i, n = arr[i]) {
return n ? n + sum(i + 1) : 0;
})(0);
const xxx = ([...str]) => [...new Set(Array.from(
{ length: str.length * 10 },
(n, i) => str.map((m, j) => (j === (i / 10 | 0)) ? i % 10 : m).join('')
))];function xxx(str) {
const arr = str.split('');
const result = [ str ];
for (const [ i, n ] of arr.entries()) {
for (let j = 0; j < 10; j++) {
if (j !== +n) {
arr[i] = j;
result.push(arr.join(''));
}
}
arr[i] = n;
}
return result;
}
hrefs.filter(n => !/\.pdf$/.test(n))
// или
hrefs.filter(n => !n.endsWith('.pdf'))
// или
hrefs.filter(n => n.split('.').pop() !== 'pdf')
// или
hrefs.filter(n => n.lastIndexOf('.pdf') !== n.length - 4)
// или
hrefs.filter(n => n.slice(-4) !== '.pdf')
// или
hrefs.filter(n => n.replace(/.*\./, '') !== 'pdf')
// или
hrefs.filter(n => n.match(/\.[^.]+$/g) != '.pdf') Что еще нужно учесть для того, чтобы во всех браузерах верстка соответствовала макету?Много чего. Например то, что сафари на макосях построен на движке хорма, НО:
li:nth-child(2) найдет второй элемент списка, т.е. второй li. А не детей этого li, как вам могло показаться. .text_footer_after_input p:nth-child(2) {}p в коде.p. function format(str) {
const s = str.length;
const chars = str.split('');
const strWithSpaces = chars.reduceRight((acc, char, i) => {
const spaceOrNothing = ((((s - i) % 3) === 0) ? ' ' : '');
return (spaceOrNothing + char + acc);
}, '');
return ((strWithSpaces[0] === ' ') ? strWithSpaces.slice(1) : strWithSpaces);
}
async function getData() {
const urls = {
comments: 'https://jsonplaceholder.typicode.com/comments',
users: 'https://jsonplaceholder.typicode.com/users',
posts: 'https://jsonplaceholder.typicode.com/posts'
}
const data = {}
for (const [key, value] of Object.entries(urls)) {
const res = await fetch(value)
data[key] = await res.json()
}
return data
}
console.log(await getData())
document.querySelectorAll('.feed__slider > :not(button)')