Masalan: console log( reverse(546) ) javob: 645, console log( reverse(1245) ) javob: 5421


Download 16.46 Kb.
Sana31.03.2023
Hajmi16.46 Kb.
#1310805
Bog'liq
functions exercises


1)Funksiya argumentiga son qabul qilsin va o’sha sonni teskarisiga qaytarsin!
Masalan: console.log( reverse(546) ) javob: 645, console.log( reverse(1245) ) javob: 5421
2)Funksiya yozing argumentida xohlagancha son olib ularning yig’indisini ekranga chiqarib bersin !
Masalan: AddNumbers(1, 2, 3) javob:6,
AddNumbers(1, 2, 3, 4, 5, 8, 9) javob:32
3)Funksiya yozing argumentida ixtiyoriy string qiymat olsin agar string teskarisiga o’qilsa ham bir xil so’z bo’lsa funksiya true aks holda false qaytarsin!
Masalan: CheckFn(“amma”) javob:true, CheckFn(“Salom”) javob:false, CheckFn(“madam”) javob:true
4)Sonning faktorialini hisoblaydigan funksiya yozing masalan: fac(5) javobi:120, chunki 5! = 1*2*3*4*5 = 120
5) funksiya tuzing o’ziga object qabul qilsin va object key value larini arrayga olib har bir array ni katta array ko’rinishida qaytarsin
Masalan: console.log(objFn({‘a’:1, ‘b’:2, ‘c’:3})),
javob :[[‘a’, 1], [‘b’, 2], [‘c’, 3]]
6) Quyidagi matritsaning qora bilan belgilangan sonlarining yig’indisini
qaytaruvchi funksiya tuzing:
Array[][] = {
{10, 11, 22, 31, 41},
{50, 60, 73, 81, 91},
{10, 11, 12, 13, 14},
{15, 16, 17, 18, 19},
{20, 21, 22, 23, 24}

7) Ikkita list berilgan faqat natural sonlardan iborat ularni birlashtirganda taribli yoki tartibli emasligini tekshiruvchi function yozing?


for example:
list1=[1,4,3,5,2];
list2=[1,8,3,6,2];
isSorted(list1,list2)// result: false

list1=[1,4,3,5,2];


list2=[8,7,6,9];
isSorted(list1,list2)// result: true

8) Ichma ich joylashgan listlar berilgan har bir list elementining ichida xoxlagancha list


bo'lishi mumkin shu listlarni sanab beradigan function yozing?

For example:


list=[1,2,[4,5,[5,[2,3],6]],[1,2]]
count(list) // result:5

9) Birinchi parametrida ko'rsatilgan listni ikkinchi parametridagi son bo'yicha listlarga joylab o'sha


listlarni bitta listga append qilib beradigan function yozing?

For example:


list = [1,2,3,4,'hello',2,6,'bye']
number = 2
group_by_ekub(list,number) // result: [[1,2],[3,4],['hello',2],[6,'bye']]
10) Berilgan string orasida bitta katta xarf bor so'zni o'sha xarfdan boshlab tartiblaydiga function yozing?

For example:


string = "kumAsslomu alay"
correction_sentence(string) // result: Asslomu alaykum

Download 16.46 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling