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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started