var today = new Date();
- var dd = today.getDate();
+ today.setDate(today.getDate() + 30);
+ var dd = today.getDate();
var mm = today.getMonth() + 1;
- let todayDate = `${dd}${mm}`
+ let todayDate = `${dd}.${mm}`
$(".date").last().text(todayDate);
function Popup(props) {
- <img onClick={props.close} />
+ <img onClick={() => props.close('передали')} />
}
const createPromiseLoop = promises => {
let index = 0;
const attach = (...args) => {
promises[index++](...args)
.then((...args) => attach(...args));
index %= promises.length;
};
return (...args) => {
attach(...args);
};
};
const sleep = (duration = 0) => new Promise(resolve => setTimeout(resolve, duration));
const loop = createPromiseLoop([
(number) => new Promise(async resolve => {
await sleep(100);
console.log(`Number plus one. Received: ${number}`);
resolve(number + 1);
}),
(number) => new Promise(async resolve => {
await sleep(100);
console.log(`Number multiply two. Received: ${number}`);
resolve(number * 2);
}),
]);
loop(1);
/*
'Number plus one. Received: 1'
'Number multiply two. Received: 2'
'Number plus one. Received: 4'
'Number multiply two. Received: 5'
'Number plus one. Received: 10'
'Number multiply two. Received: 11'
'Number plus one. Received: 22'
'Number multiply two. Received: 23'
'Number plus one. Received: 46'
'Number multiply two. Received: 47'
'Number plus one. Received: 94'
'Number multiply two. Received: 95'
'Number plus one. Received: 190'
'Number multiply two. Received: 191'
'Number plus one. Received: 382'
'Number multiply two. Received: 383'
'Number plus one. Received: 766'
'Number multiply two. Received: 767'
'Number plus one. Received: 1534'
'Number multiply two. Received: 1535'
'Number plus one. Received: 3070'
'Number multiply two. Received: 3071'
'Number plus one. Received: 6142'
'Number multiply two. Received: 6143'
'Number plus one. Received: 12286'
'Number multiply two. Received: 12287'
'Number plus one. Received: 24574'
*/
Q
?const magic = size => {
const rows = [];
const template = '.'.repeat(size);
for (let row = 0; row < size; row++) {
const index = Math.floor(Math.random() * size);
const value = `${template.slice(0, index)}Q${template.slice(index + 1)}`;
rows.push(value);
}
return rows.join('\n');
};
console.log(magic(10));
/*
...Q......
......Q...
Q.........
.........Q
....Q.....
......Q...
.Q........
.....Q....
..Q.......
....Q.....
*/
const expression = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
const emails = [
`simple@example.com`,
`very.common@example.com`,
`disposable.style.email.with+symbol@example.com`,
`other.email-with-hyphen@example.com`,
`fully-qualified-domain@example.com`,
`user.name+tag+sorting@example.com`,
`x@example.com`,
`example-indeed@strange-example.com`,
`admin@mailserver1`,
`example@s.example`,
`" "@example.org`,
`"john..doe"@example.org`,
`mailhost!username@example.org`,
`user%example.com@example.org`,
];
for (const email of emails) {
console.log(email, expression.test(email));
}
/*
'simple@example.com' true
'very.common@example.com' true
'disposable.style.email.with+symbol@example.com' true
'other.email-with-hyphen@example.com' true
'fully-qualified-domain@example.com' true
'user.name+tag+sorting@example.com' true
'x@example.com' true
'example-indeed@strange-example.com' true
'admin@mailserver1' false
'example@s.example' true
'" "@example.org' true
'"john..doe"@example.org' true
'mailhost!username@example.org' true
'user%example.com@example.org' true
*/
- var element = document.getElementById('portfolio-content-nav') + window.pageYOffset + 'px';
+ var element = document.getElementById('portfolio-content-nav');
window.addEventListener('scroll', function () {
- if (element > 100) {
+ if (window.scrollY > 100) {
element.classList.add("shadow");
} else {
element.classList.remove("shadow");
}
});
const camelToSnake = (string, toUpper = false) => {
const preparedString = string.replace(/[A-Z]/g, '_$&');
return toUpper ? preparedString.toUpperCase() : preparedString.toLowerCase();
};
window.addEventListener('DOMContentLoaded', () => {
const params = new URLSearchParams(location.search);
const keys = params.keys();
for (const key of keys) {
const field = document.querySelector(`input[name="${camelToSnake(key, true)}"]`);
if (field !== null) {
field.value = params.get(key);
}
}
});
const calculateFinalAmount = cart => {
return cart.reduce((cartTotal, record) => {
const recordTotal = record.products.reduce((recordTotal, product) => {
return recordTotal + parseFloat(product.price) * product.quantity;
}, 0);
return cartTotal + recordTotal;
}, 0);
};
// # 17
function f(x, y) {
if (x * y < 0.5) {
return (4 + Math.sin(y - x)) / (x / y + Math.pow(x, 2));
} else {
return Math.cos(Math.log(x / y)) - 4;
}
}
function calc(x, y) {
return Math.pow(Math.sin(f(x, y)), 3);
}
Array[j][i] = getRamdomEl()
Ai
вы достучитесь, а до Aj
как? Сначала Вам необходимо добавить по Ai
пустой массив, и только потом добавлять в него числа.function getColumnsMax(matrix, rows, columns) {
const maxValues = [];
for (let column = 0; column < columns; column++) {
const columnValues = [];
for (let row = 0; row < rows; row++) {
columnValues.push(matrix[row][column]);
}
maxValues.push(Math.max(...columnValues));
}
return maxValues;
}
const url = "/animals/15";
const urlList = ['/animals/cats', 'animals/details/subdetails/:id', '/animals/:id', 'smth/else', 'smth/else/:id/:type'];
const matchURL = (url, list) => {
const count = list.length;
for (let index = 0; index < count; index++) {
const template = list[index];
const preparedTemplate = template.replace(/:(\w+)/g, '(?<$1>[^/]+)');
const expression = new RegExp(`^${preparedTemplate}$`, 'gi');
const match = expression.exec(url);
if (match !== null) {
return {
index,
url,
template,
params: match?.groups || {}
};
}
}
return null;
};
matchURL(url, urlList);
/*
{
index: 2,
url: '/animals/15',
template: '/animals/:id',
params: { id: '15' }
}
*/
fetch('https://jsonplaceholder.typicode.com/users/9')
.then(function(response) {
- console.log(response.json());
+ return response.json();
})
.then(function(data) {
console.log(data);
})
.catch(function(error) {
console.log('error');
})