সমস্যা
আমাদের একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা সংখ্যার একটি মিশ্র অ্যারে এবং পূর্ণসংখ্যার স্ট্রিং উপস্থাপনা নেয়৷
আমাদের ফাংশনে okthe স্ট্রিং পূর্ণসংখ্যা যোগ করা উচিত এবং মোট নন-স্ট্রিং পূর্ণসংখ্যা থেকে এটি বিয়োগ করা উচিত।
উদাহরণ
নিম্নলিখিত কোড -
const arr = [5, 2, '4', '7', '4', 2, 7, 9];
const integerDifference = (arr = []) => {
let res = 0;
for(let i = 0; i < arr.length; i++){
const el = arr[i];
if(typeof el === 'number'){
res += el;
}else if(typeof el === 'string' && +el){
res -= (+el);
};
};
return res;
};
console.log(integerDifference(arr)); আউটপুট
নিম্নোক্ত কনসোল আউটপুট -
10