const parseDate = (date) => Date.parse(date.split('/').reverse().join('-'));
const findClosest = (list, date = (new Date()).toLocaleDateString('en-GB')) => {
const findDate = parseDate(date);
return list.reduce(
(acc, cur) => {
const delta = parseDate(cur.date) - findDate;
return (delta >= 0 && delta < acc.delta) ? { delta, el: cur } : acc;
},
{ delta: Number.MAX_SAFE_INTEGER, el: null },
).el;
};
deepEqual({a: 1}, {b: 1}); // true
deepEqual(null, {b: 1}); // 1
deepEqual({a: 1, b: 2}, {b: 2, a: 1}); // false
const deepEqual = (a, b) => {
if (a === b) {
return true;
}
if (a === null || b === null || typeof a !== 'object' || typeof b !== 'object') {
return false;
}
const aKeys = Object.keys(a);
const bKeys = Object.keys(b);
if (aKeys.length !== bKeys.length) {
return false;
}
for (let i = 0; i < aKeys.length; i += 1) {
const key = aKeys[i];
if (!bKeys.includes(key) || !deepEqual(a[key], b[key])) {
return false;
}
}
return true;
};
listToArray(arrayToList([1, 2, 3])); // Array(3) [ 3, 2, 1 ]
const list = {
value: 2,
rest: {
value: 3,
rest: null,
},
};
prepend(1, list);
/*
Object {
value: 1,
rest: Object {
value: 3,
rest: Object {
value: 2,
rest: null
}
}
}
*/
const arrayToList = (arr, idx = 0) => ({
value: arr[idx],
rest: idx === arr.length - 1
? null
: arrayToList(arr, idx + 1)
});
const listToArray = (list) => (
list.rest === null
? [list.value]
: [list.value, ...listToArray(list.rest)]
);
const prepend = (value, rest) => ({ value, rest });
const nth = (list, idx) => (
idx === 0
? list.value
: (
list.rest === null
? undefined
: nth(list.rest, idx - 1)
)
);
const arrayToList = (arr) => {
const list = null;
for (let i = arr.length - 1; idx >= 0; idx -= 1) {
list = { value: arr[idx], rest: list };
}
return list;
};
const listToArray = (list) => {
const arr = [];
while (list !== null) {
arr.push(list.value);
list = list.rest;
}
return arr;
};
const prepend = (value, rest) => ({ value, rest });
const nth = (list, idx) => {
while (list !== null) {
if (idx === 0) {
return list.value;
}
idx -= 1;
list = list.rest;
}
};
const test = (x) => { console.log(x); return false; };
if (test(1) && test(2)) {
console.log('???');
}
const NAMESS = [];
while (NAMESS.length < 8) {
const rand = `${NAMES[random(0, NAMES.length - 1)]} ${SURNAMES[random(0, SURNAMES.length - 1)]}`;
if (!NAMESS.includes(rand)) {
NAMESS.push(rand);
}
}
[0, 1, 2, 3, 4].map(
(shift) => {
const date = new Date();
date.setDate(date.getDate() + shift);
return date.toLocaleDateString('en-CA');
}
);
// Array(5) [ "2022-03-28", "2022-03-29", "2022-03-30", "2022-03-31", "2022-04-01" ]
const date = new Date();
const dates = [];
for (i = 0; i < 5; i += 1) {
dates.push(date.toLocaleDateString('en-CA'));
date.setDate(date.getDate() + 1);
}
console.log(dates);
// Array(5) [ "2022-03-28", "2022-03-29", "2022-03-30", "2022-03-31", "2022-04-01" ]
JSON.parse('"\u042d\u0442\u043e \u0442\u0435\u043a\u0441\u0442 \u043a\u043e\u0442\u043e\u0440\u044b \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0439 \u0444\u0438\u0433\u043d\u0451\u0439 \u0437\u0432\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d \u0438 \u0431\u043e\u0433 \u0437\u043d\u0430\u0435\u0442 \u043a\u0430\u043a \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u043c"');
// Это текст которы непонятной фигнёй звкодирован и бог знает как его обратно сделать нормальным
onStart() {
let idx = 0;
const timer = setInterval(
() => {
this.step = this.myList[idx];
idx += 1;
if (idx >= this.myList.length) {
clearInterval(timer);
}
},
1000,
);
}