Skip to content

Latest commit

 

History

History
22 lines (16 loc) · 668 Bytes

a_needle_in_the_haystack.md

File metadata and controls

22 lines (16 loc) · 668 Bytes

Description

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"

My Solution

def find_needle(haystack)
  "found the needle at position #{haystack.index('needle')}"
end