আমাদের একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা নম্বর অ্যারে নেয় এবং অ্যারে থেকে উপাদান প্রদান করে যা উভয়ের জন্য সাধারণ নয়।
উদাহরণস্বরূপ, যদি দুটি অ্যারে −
হয়const arr1 = [2, 4, 2, 4, 6, 4, 3]; const arr2 = [4, 2, 5, 12, 4, 1, 3, 34];
আউটপুট
তারপর আউটপুট −
হওয়া উচিতconst output = [ 6, 5, 12, 1, 34 ]
উদাহরণ
এর জন্য কোড হবে −
const arr1 = [2, 4, 2, 4, 6, 4, 3];
const arr2 = [4, 2, 5, 12, 4, 1, 3, 34];
const deviations = (first, second) => {
const res = [];
for(let i = 0; i < first.length; i++){
if(second.indexOf(first[i]) === -1){
res.push(first[i]);
}
};
for(let j = 0; j < second.length; j++){
if(first.indexOf(second[j]) === -1){
res.push(second[j]);
};
};
return res;
};
console.log(deviations(arr1, arr2)); আউটপুট
কনসোলে আউটপুট -
[6, 5, 12, 1, 34 ]