reduce()
в копилку:const zip = (arr1, arr2) => arr1.reduce(
(acc, head, i) => (acc.push({ ...arr2[i], head }), acc),
[]
);
zip(mass1, mass2)
/* [
{ t1: "aa", p1: "lot", head: "zn1" },
{ t1: "ab", p1: "kot", head: "zn2" },
{ t1: "ac", p1: "mot", head: "zn3" },
] */
map()
тут больше подходит:mass1.map((head, i) => ({ head, ...mass2[i] }))
let mass1 = ["zn1", "zn2", "zn3"]
let mass2 = [
{t1: "aa", p1: "lot"},
{t1: "ab", p1: "kot"},
{t1: "ac", p1: "mot"}
]
let mass3 = []
for (let i = 0; i < mass1.length; i++) {
mass3.push(
Object.assign(mass2[i], {head: mass1[i]})
)
}
[...new Map(arr.map((item) => [item["key"], item])).values()]
const uniqueIds = [];
arr.filter(element => {
const isDuplicate = uniqueIds.includes(element.key);
if (!isDuplicate) {
uniqueIds.push(element.key);
return true;
}
return false;
});
Object.values(
arr.reduce( (c, e) => {
if (!c[e.key]) c[e.key] = e;
return c;
}, {})
);
const unique = (arr, key) => {
const keys = new Set();
return arr.filter(el => !keys.has(el[key]) && keys.add(el[key]));
};
unique(arr, 'key')
value
.- let input = document.getElementsByClassName('form-control');
+ const input = document.querySelector('input.form-control');
0 0 500 500
- всё будет работать, просто бублик будет в 10 раз меньше.viewBox
- задаёт систему координат для вложенных элементов. Т.е. width
у тебя 500px - эти 500px, размечены на отрезки от 0 до 50. Т.е. 1
-> 10px
, r="15.9"
-> r="159px".
Всё просто. document.querySelector('.close').addEventListener('click', function(e){
e.stopPropagation()
document.querySelector('.result').insertAdjacentHTML('beforeend', '<div>Close</div>');
});
// вспомогательная функция
function countDig(n, pow, pow10, pow9) {
const dig = n / pow10;
const count = dig < 6n ? dig : dig - 1n;
return count * pow9 + (dig === 5n || pow < 1n ? 0n : countDig(n % pow10, pow - 1n, pow10 / 10n, pow9 / 9n));
}
// количество беспятёрочников на отрезке [0...n-1]
function countWithout5(n) {
let pow = 0n, pow10 = 1n;
while (pow10 * 10n <= n) {
pow++;
pow10 = pow10 * 10n;
}
return countDig(n, pow, pow10, 9n ** pow);
}
function count(min, max) {
if (min > max) {
return 0n;
}
if (min >= 0n) {
return countWithout5(max + 1n) - countWithout5(min);
}
if (max <= 0n) {
return countWithout5(1n - min) - countWithout5(-max);
}
return countWithout5(max + 1n) + countWithout5(1n - min) - 1n;
}
count(4n, 17n); // 12n
count(-3455534n, 1731643265265475472546254726454363145657453757347547n);
// результат 7912695757329425999049503116097171379949505558054n