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

find_needle(['hay', 'junk', 'hay', 'hay', 'moreJunk', 'needle', 'randomJunk'])

find_needle(['hay', 'junk', 'hay', 'hay', 'moreJunk', 'needle', 'randomJunk'])

findNeedle(['hay', 'junk', 'hay', 'hay', 'moreJunk', 'needle', 'randomJunk'])

findNeedle(new Object[] {"hay", "junk", "hay", "hay", "moreJunk", "needle", "randomJunk"})

find_needle(["hay", "junk", "hay", "hay", "moreJunk", "needle", "randomJunk"])

should return

'found the needle at position 5'

'found the needle at position 5'

'found the needle at position 5'

"found the needle at position 5"

"found the needle at position 5"

Kata's link: Sum of many ints

Best Practices

PY First:

def find_needle(haystack):
  return 'found the needle at position {}'.format(haystack.index('needle'))

results matching ""

    No results matching ""