Question: JavaScript beginner problem: Write a function `chooseyEndings` that accepts an array of words and a suffix string as arguments. The function should return a new

JavaScript beginner problem:

Write a function `chooseyEndings` that accepts an array of words and a suffix string as arguments. The function should return a new array containing the words that end in the given suffix. If the value passed in is not an array, return an empty array. Solve this using Array's `filter()` method.

HINT: There are built in JavaScript functions that will help with determining if a string ends a certain way.

Given function starter:

let chooseyEndings = function (words, suffix) {

}

Examples:

console.log(chooseyEndings(['family', 'hound', 'catalyst', 'fly', 'timidly', 'bond'], 'ly')); // [ 'family', 'fly', 'timidly' ]

console.log(chooseyEndings(['family', 'hound', 'catalyst', 'fly', 'timidly', 'bond'], 'nd')); // [ 'hound', 'bond' ]

console.log(chooseyEndings(['simplicity', 'computer', 'felicity'], 'icity')); // [ 'simplicity', 'felicity' ]

console.log(chooseyEndings(['simplicity', 'computer', 'felicity'], 'ily')); // [ ]

console.log(chooseyEndings(17, 'ily')) // [ ]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!