const nextAfter = (arr, value) => {
const ind = arr.indexOf(value)
if (ind < 0) return
return arr[ind + 1] // для предыдущего -1
}
arr.find((v, ind, arr) => arr[ind - 1] === value)
// для предыдущего +1, не путать с первым примером
const obj = name.reduce((agg, v, ind) => {
agg[v] = (agg[v] || 0) + price[ind]
return agg
}, {})
const nameNew = Object.keys(obj)
const priceNew = Object.values(obj)
const [nameNew, priceNew] =
_.unzip(
_.toPairs(
_.groupBy(
_.zip(name, price).map(([name, price]) => ({ name, price })),
'name'
)
).map(([name, prices]) => [name, _.sumBy(prices, 'price')])
)
let [withAge, withoutAge] = users.reduce((agg, v) => {
agg['age' in v].push(v)
return agg
}, [[], []])
const sorted = [...withAge.sort((a, b) => a.age - b.age), ...withoutAge]
let [withoutAge, withAge] = _.partition(users, ({ age }) => age)
const sorted = [..._.sort(withAge, 'age'), ...withoutAge]
const farest (element, selector, secondCall) {
const parent = element.closest(selector)
return parent ? farest(parent, selector, true) : secondCall && element
}
const arrowFuncSquare = (param) => param * param
// Не нужен return, стрелочная однострочная функция без фигурных скобок
const arrowFuncSquare2 = (param) => {
if (param) return param * 2
else return param
} // Нужен return, потому что фигурные скобки
const addTime = param => {
param.createdAt = moment()
param.updatedAt = moment()
} // Не нужен return, потому что функция не возвращает значения
const addTime = param => {
if (param.timeless) return
param.createdAt = moment()
param.updatedAt = moment()
} // Нужен return чтобы при определенном условии прерывать выполнение кода функции
const str = `
RAM_smith_T1:0 "Anführer von Amerika"
RAM_smith_T2:0 "Popular"
RAM_smith_T3:0 "Suppressor of the Resistance"
RAM_smith_T4:0 "Folower of the Reich's Orders"
RAM_smith_T5:0 "Tied by German Oligarchy"
umc_leader_john_smith_ram_desc:0 ""`
const regExp = (/:0 "([^"]+)"/ig)
let found
while (found = regExp.exec(str)) {
console.log(found[1])
}
onMouseMove={e => { this.mouse = { clientX: e.clientX, clientY: e.clientY }} }
const rect = document.querySelector('.Message').getBoundingClientRect()
if (this.mouse.clientX < rect.left ||
this.mouse.clientX > rect.right ||
this.mouse.clientY < rect.top ||
this.mouse.clientY > rect.bottom) {
this.disable()
}
document.querySelector('.Message')
arr[i] % 0 +`${s}`+ 0
function getSameParity(arr){
const newArr = [];
let s = arr[0] % 2;
for(let i = 0; i < arr.length; i += 1){
if(arr[i] % 2 === s){
newArr.push(arr[i]);
}
}
return newArr;
}
console.log(getSameParity([3, 6, 7, 8])) // [3, 7]
console.log(getSameParity([4, 6, 7, 8])) // [4, 6, 8]
const getSameParity = arr => arr.filter(v => v % 2 === arr[0] % 2)