const check = (angle) => {
if (angle > 360) {
return;
}
const targetAngles = [0, 45, 90, 135, 180, 225, 270, 315, 360];
let lastResult = Number.MAX_SAFE_INTEGER;
for (let i = 0; i < targetAngles.length; i++) {
let diff = Math.abs(angle - targetAngles[i]);
if (diff < lastResult) {
lastResult = diff;
} else {
return targetAngles[i - 1];
}
}
}
const strLenght = (string) => {
const iter = (n) => {
if (string[n] === undefined) {
return n;
}
return iter(++n);
};
return iter(0);
};
let arr = document.querySelectorAll('.item');
arr.forEach((elem)=>{
elem.style = "background: green";
});
arr[0].style = 'background:red';
for ( let i=1; i<arr.length; i++ ){
arr[i].style = 'background:red';
arr[i-1].style = 'background:green';
};