Sobes.tech
Junior — Middle+

Selection of tasks containing a separate word

livecode

Task condition

It is necessary to implement the filterTasks function, which takes an array of task strings and a filter word, and returns only those tasks where the specified word appears as a separate token, not as part of another word.

const tasks = [
  "Buy tea",
  "Buy teapot",
  "Call grandma",
  "Make tea with lemon",
  "Learn JavaScript"
];

filterTasks(tasks, "tea");   // ["Buy tea", "Make tea with lemon"]
filterTasks(tasks, "java");  // ["Learn JavaScript"]
filterTasks(tasks, "nik");   // ["Buy teapot"]

The function should correctly handle case sensitivity and consider word boundaries to exclude matches inside other words.