Sentence Searcher II

Published by Deep Xavier in

Create a function that returns the sentence that contains the word at index n. Remember to include the full stop at the end.

Worked Example

final String txt = "I love Tesh. My world evolves in hers. My love for life.";

sentenceSearcher(txt, 4) ➞ "My world evolves in hers."
// The word at index 4 is "world".
// The full sentence that contains the word at index 4 is "My world evolves in hers."

Examples

sentenceSearcher(txt, 2) ➞ "I love Tesh."

sentenceSearcher(txt, 5) ➞ "My world evolves in hers."

sentenceSearcher(txt, -1) ➞ "My love for life."
// The index at -1 is the last word.
// The last word is "life".

Notes

  • All sentences will end with a full stop.
  • You need to account for negative indexes as well.
Watch a quick demo on how Edabit works.