Write a function filterWords(words, part) that returns the words from the array words that contain part as a substring. For ['ant', 'tiger', 'elephant'] and 'ant' the answer is ['ant', 'elephant'].
words is an array of words (it can be empty). part is a non-empty string of letters.'ant' the words 'Antelope' and 'PLANT' match too, and 'ANT' as part finds 'plant'.part can be anywhere in the word: at the start, in the middle or at the end.words.includes and filter do most of the work.
filterWords(['ant', 'tiger', 'elephant'], 'ant')Returns [ 'ant', 'elephant' ]
filterWords(['Antelope', 'cat', 'PLANT'], 'ant')Returns [ 'Antelope', 'PLANT' ]
filterWords(['dog', 'cat'], 'ant')Returns []
Asked at Nvidia · Source
filterWords([ 'ant', 'tiger', 'elephant', 'pants' ], 'ant')[ 'ant', 'elephant', 'pants' ]filterWords([ 'dog', 'cat' ], 'ant')[]Hidden tests run on Submit.