javascript Challenge: prioritize Create a function prioritize that accepts an array and a callback. The callback will re

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

javascript Challenge: prioritize Create a function prioritize that accepts an array and a callback. The callback will re

Post by answerhappygod »

javascript
Challenge: prioritize
Create a function prioritize that accepts an array and
a callback. The callback will return
either true or false. prioritize will
iterate through the array and perform the callback on each element,
and return a new array, where all the elements that yielded a
return value of true come first in the array, and the
rest of the elements come second.
//add your code
// function startsWithS(str) { return str[0].toLowerCase() ===
's'; }
// const tvShows = ['curb', 'rickandmorty', 'seinfeld', 'sunny',
'friends']
// console.log(prioritize(tvShows, startsWithS)); // should log:
['seinfeld', 'sunny', 'curb', 'rickandmorty', 'friends']
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply