async function fnOne() {
return new Promise(res=>setTimeout(()=>{res(1000)}, 1000))
}
async function fnTwo() {
return new Promise(res=>setTimeout(()=>{res(2000)}, 1200))
}
async function fnThree() {
return new Promise(res=>setTimeout(()=>{res(3000)}, 1400))
}
const allFn = async ()=>{
try {
await fnOne()
console.log('Выполнилась 1-я ф-ция')
const rz = await fnTwo()
console.log('Выполнилась 2-я ф-ция, полученный результат = ', rz)
await fnThree()
console.log('Выполнилась 3-я ф-ция')
}catch (e) {
console.error(e)
}
}
allFn()
function animateWord(word){
let text = word.dataset.text;
text.split('').forEach((letter,ind) => {
let div = document.createElement('div');
div.innerText = letter;
setTimeout(()=> word.append(div),ind*200);
})
}
const word = document.querySelector('.word');
animateWord(word);
@keyframes letter{
0% {opacity: 0; transform: translateY(-15px)}
100% {opacity: 1; transform: translateY(0px)}
}
.word div {
animation: letter 0.5s;
display: inline-block;
}
<div class="word" data-text='Hello'></div>
const newData = data.reduce((acc, n) => {
const k = Object.keys(n)[0];
(acc.result[acc.keys[k] = (acc.keys[k] ?? -1) + 1] ??= []).push(n);
return acc;
}, { result: [], keys: {} }).result.flat();
const numKeys = new Set(data.flatMap(Object.keys)).size;
const numObjs = data.length / numKeys;
const newData = data.map((n, i, a) => a[(i % numKeys) * numObjs + (i / numKeys | 0)]);
{ "кришна": 4, "харе": 4, ":-O": 1 }
Оставить только те, где значения 1. Собрать в массив.const unique = arr => arr.filter((item, i) => i === arr.indexOf(item) && i === arr.lastIndexOf(item));
const simpleString = '7911xxxxxxx';
const validateStr = (str) => {
let result = '';
if (typeof str !== 'string') throw 'Parameter is not a string!';
if (str.length >= 10) throw 'Phone is incorrect!';
if (str[0] === '7') result = '+' + str;
return str;
}
const records =[
{'name' :'Pink Floyd The Dark Side of the Moon'},
{'year': '1973'},
{'country': 'london'},
{'date': 'March 24'},
{'type':'music album'},
{'name' :'Dark Side of the Moon'},
{'year': '1986'},
{'country': 'paris'},
{'date': 'March 14'},
{'type':'video album'},
]
// сначала разбиваем на массив по 5 объектов
const nz = records.reduce((acc,c,i,arr) => {
if ((i % 5) === 0) acc.push([]);
acc[acc.length - 1].push(c);
return acc;
}, [])
// затем сливаем объекты
const rez = nz.map(ob=>{
return Object.assign({}, ...ob)
})
// результат
console.log(rez)
let result = [];
let num = 0;
let obj;
records.forEach(e => {
if (num++ === 0) result.push(obj = {});
Object.assign(obj, e);
if (num === 5) num = 0;
});
console.log(result);
//но можно сделать короче и красивее
const obj = [{
'name': 'anna',
'lastname': 'petrova'
},
{
'name': 'vika',
'lastname': 'ivanova'
},
{
'name': 'julia',
'lastname': 'petrova'
},
];
const res = obj.reduce((o, i) => {
if (!o.find(v => v.lastname == i.lastname)) {
o.push(i);
}
return o;
}, []);
console.log(res)