Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

0201844524, 978-0201844528

More Books

Students also viewed these Databases questions

Question

5. Recognize your ability to repair and let go of painful conflict

Answered: 1 week ago