Sizga berilgan massiv ichida bir nechta foydasiz narsalar (junk) mavjud, lekin ular orasida "needle" (igna) ham bor.
Sizning vazifangiz:
"needle" so‘zini massivdan topish.
Uni topgach, quyidagi xabarni string ko‘rinishida qaytarish:
"found the needle at position " + "needle" so‘zi turgan indeks.
Misol:
Agar massiv shunday bo‘lsa:
["hay", "junk", "hay", "hay", "moreJunk", "needle", "randomJunk"]
masala kodi:
function findNeedle(haystack) {
const index = haystack.indexOf("needle");
return `found the needle at position ${index}`;
}
Sizning vazifangiz:
"needle" so‘zini massivdan topish.
Uni topgach, quyidagi xabarni string ko‘rinishida qaytarish:
"found the needle at position " + "needle" so‘zi turgan indeks.
Misol:
Agar massiv shunday bo‘lsa:
["hay", "junk", "hay", "hay", "moreJunk", "needle", "randomJunk"]
masala kodi:
function findNeedle(haystack) {
const index = haystack.indexOf("needle");
return `found the needle at position ${index}`;
}