다음과 같은 경우 배열은 특수 배열입니다. -
--All the elements at odd indices are odd. --All the elements at even indices are even.
배열을 받아 특수 배열인지 확인하는 JavaScript 함수를 작성해야 합니다.
예시
다음은 코드입니다 -
const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
const isSpecial = (arr = []) => {
for(let i = 0; i < arr.length; i++){
if(arr[i] % 2 === i % 2){
continue;
};
return false;
};
return true;
};
console.log(isSpecial(arr)); 출력
다음은 콘솔의 출력입니다 -
true