function rgbaToAndroid1(rgba) {
const c = new Uint8Array([
rgba[2],
rgba[1],
rgba[0],
Math.round(rgba[3] * 255)
]);
return new Uint32Array(c.buffer)[0];
}
// либо
function rgbaToAndroid2(rgba) {
let color = 0;
for (let i = 0; i < 3; i++) {
color += rgba[i] * 2 ** ((2 - i) * 8);
}
color += Math.round(rgba[3] * 255) * 2 ** (3 * 8);
return color;
}
console.log(rgbaToAndroid1([255, 122, 107, 1]));
console.log(rgbaToAndroid2([255, 122, 107, 1]));
function createTable(el) {
for (let i = 0, row; i < el.length; i++) {
if (i % 7 === 0) {
row = document.createElement('tr');
thead.appendChild(row);
}
const cell = document.createElement('th');
cell.innerHTML = el[i];
row.appendChild(cell);
}
}
function checkingReading() {
let prevTimeStamp = performance.now();
chatbox.addEventListener("DOMSubtreeModified", (e) => {
const dt = e.timeStamp - prevTimeStamp;
prevTimeStamp = e.timeStamp;
const changesPerSecond = 1000 / dt;
console.log(changesPerSecond)
});
}
function arrayToList(array) {
const last = array.length - 1;
return {
value: array[last],
rest: last === 0 ? null : arrayToList(array.slice(0, last))
};
}function arrayToList(array, idx = array.length - 1) {
return {
value: array[idx],
rest: idx === 0 ? null : arrayToList(array, idx - 1)
};
}