const info = {
10: {
5: {
title: 'BORRI INGENIO COMPACT <br> 10 kVA (BSS90)',
description: 'Мощность 10 000 Вт/Ва',
...
},
10: {
title: 'BORRI INGENIO COMPACT <br> 10 kVA (BSS90)',
description: 'Мощность 10 000 Вт/Ва',
...
},
},
};
document.onmousemove = function(e) {
const slider1value = $("#slider1").roundSlider("option", "value");
const slider2value = $("#slider2").roundSlider("option", "value");
$('.calc_nazvanie').html(info[slider1value][slider2value].title);
$('.calc_descr').html(info[slider1value][slider2value].description);
...
}
function CSVToArray(strData, strDelimiter = ','){
const objPattern = new RegExp(
"(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +
"(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +
"([^\"\\" + strDelimiter + "\\r\\n]*))",
'gi'
);
const arrData = [[]];
let arrMatches = null;
while (arrMatches = objPattern.exec(strData)){
const strMatchedDelimiter = arrMatches[ 1 ];
if (
strMatchedDelimiter.length &&
strMatchedDelimiter !== strDelimiter
) {
arrData.push([]);
}
const strMatchedValue = arrMatches[2]
? arrMatches[2].replace(new RegExp("\"\"", 'g' ), "\"")
: arrMatches[3];
arrData[arrData.length - 1].push(strMatchedValue);
}
return( arrData );
}
console.log(CSVToArray('"a,b",a b,')); // Array(3) [ "a,b", "a b", "" ]
function shortNumber(val) {
const degree = Math.floor(Math.log10(val) / 3);
const suffix = ['', ' тыс.', ' млн', ' млрд'][degree];
const num = val / (10 ** (degree * 3));
return `${num.toFixed(num >= 10 ? 0 : 1)}${suffix}`;
}
shortNumber(123); // "123"
shortNumber(12345); // "12 тыс."
shortNumber(1234567); // "1.2 млн"
JavaScript RegExp objects are stateful when they have the global or sticky flags set (e.g., /foo/g or /foo/y). They store a lastIndex from the previous match. Using this internally, test() can be used to iterate over multiple matches in a string of text (with capture groups).Кратко - с опциями g и y объект RegExp сохраняет позицию, с которой продолжает поиск при следующем вызове. У вас одинаковые строки и второй вызов начинает с позиции, на которой закончился первый вызов, то есть уже после '.mp3'.
countCookies(3, 6, [0, 0, 0]); // 1
countCookies(3, 2, [0, 2, 2]); // 0
- const allCookies = cookies.reduce((sum, acc) => sum + acc, 0);
- let maxCookies = Number(Math.max.apply(null, cookies));
+ const maxCookies = Math.max(...cookies);
- let sum = cookies.reduce((acc, c) => acc + Math.floor((c + K - 1) / K), 0);
+ const sum = cookies.reduce((acc, c) => acc + Math.ceil(c / K), 0);