function debounce(f, ms) {
let isRunning = false;
return function() {
if (isRunning) return;
f.apply(this, arguments);
isRunning = true;
setTimeout(() => isRunning = false, ms);
};
}
function myFunction {
console.log('i am working');
}
const debouncedMyFunction = debounce(myFunction, 2000);
debouncedMyFunction(); // Выполнится
debouncedMyFunction(); // Будет проигнорирована this.array.splice(oldElementIndex, 1, newElement)this.$set(this.array, oldElementIndex, newElement)this.array = this.array.map(el => {
el.someParam = 1
return el
}) async getAllUsers() {
const { data: users } = await axios.get('http://jsonplaceholder.typicode.com/users')
this.posts = this.posts.map(p => {
p.author = users.find(u => u.id === p.userId)
return p
})
},const filename = 'file.ext'
const ext = filename.split('.')[1] // 'ext'const filename = 'file.ext'
const extSplitted = filename.split('.')
cosnt ext = extSplitted[extSplitted.length - 1]. // 'ext'const filename = 'file.jpg'
const matched = filename.match(/jpg|mp3|png|mp4/)
if (matched !== null) console.log('file extension is:', matched[0])const filename = 'file.jpg'
const matched = filename.replace(/\w+/, '').replace('.', '')
console.log(matched) // 'jpg' const copyOfArray = JSON.parse(JSON.stringify(sourceArray))const f = (arr = []) => {
arr.push(1)
arr.push(2)
return arr
}
const basicArr = f([]) // [1,2]
f(basicArr)
console.log(basicArr) // [1, 2, 1, 2] data()data: () => ({ param: 1 }) //Возвращает объектdata: () => {
return {
param: 1
}
}this.inputs.forEach((value, index) => {
this.$set(this.inputs, index, {...value, label: value.label1})
});this.inputs = this.inputs.map(item => ({ ...item, label: item.label1 }))const obj = { a: 100, b: 152, c: { y: 133, x: { m: 20} } }
const flatObject = (current) => {
return Object.keys(current).reduce((acc, cur) => {
if (typeof(current[cur]) !== 'object') {
acc[cur] = current[cur]
} else {
acc = {...acc, ...flatObject(current[cur]) }
}
return acc
}, {})
}
console.log(flatObject(obj)) async function getChannel(urlChannel){
const urlChannelResult = await fetch(urlChannel)
const jsonChannel = await urlChannelResult.json()
const authorPhoto = jsonChannel.items[0].snippet.thumbnails.high.url
console.log(authorPhoto
return authorPhoto
}
[...].map(async el => {
const authorPhoto = await getChannel(el.url)
// ....
}) {
reply_markup: {
inline_keyboard: [
[{ text: 'but 1', callback_data: 'but1data' }, { text: 'but 2', callback_data: 'but2data' }],
[{ text: 'but 3', callback_data: 'but3data' }],
[{ text: 'but 4', callback_data: 'but4data' }, { text: 'but 5', callback_data: 'but5data' }],
[{ text: 'but 6', callback_data: 'but6data' }]
]
}
}