একটি অ্যারে হল একটি বিশেষ অ্যারে যদি −
--All the elements at odd indices are odd. --All the elements at even indices are even.
আমাদের একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা একটি অ্যারে নেয় এবং এটি বিশেষ অ্যারে কিনা তা পরীক্ষা করে।
উদাহরণ
নিম্নলিখিত কোড -
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