Faqat sonlarni ajratish
Array ichida faqat number turidagi qiymatlarni ajratib, yangi array qaytaradigan funksiya yozing.
Masala
Array ichida faqat number tipidagi qiymatlarni ajratib, yangi array qaytaring.
- Funksiya nomi:
onlyNumbers - Parametr: turli tipdagi qiymatlar bo‘lishi mumkin bo‘lgan array
items - Natija: faqat
typeof value === "number"bo‘lgan elementlardan iborat yangi array
Misollar
onlyNumbers([1, "2", 3]); // [1, 3]
onlyNumbers([10, true, "5", 2]); // [10, 2]
onlyNumbers(["a", false, null]); // []
console.log(...) orqali tekshiring.
Practice & Try It Out
SolvedNote: Use console.log() to print output
Write your code here and click "Run" to see the output
Output