반응형
Can you find the needle in the haystack?
Write a function findNeedle() that takes an array full of junk but containing one "needle"
After your function finds the needle it should return a message (as a string) that says:
"found the needle at position " plus the index it found the needle, so:
Example(Input --> Output)
["hay", "junk", "hay", "hay", "moreJunk", "needle", "randomJunk"] --> "found the needle at position 5"
Note: In COBOL, it should return "found the needle at position 6"
Solution:
const findNeedle = haystack => `found the needle at position ${haystack.indexOf("needle")}`
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
0111. You Can't Code Under Pressure #1 (0) | 2023.01.12 |
---|---|
0110. altERnaTIng cAsE <=> ALTerNAtiNG CaSe (0) | 2023.01.11 |
0108. How many lightsabers do you own? (0) | 2023.01.09 |
0107. Exclamation marks series #4: Remove all exclamation marks from sentence but ensure a exclamation mark at the end of string (0) | 2023.01.07 |
0106. Is there a vowel in there? (0) | 2023.01.07 |