हमें एक जावास्क्रिप्ट फंक्शन लिखना है जो नंबर ऐरे ले और दोनों के लिए कॉमन न होने वाले एलिमेंट्स वापस करे।
उदाहरण के लिए, यदि दो ऐरे हैं:
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 ]