mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
986 B
986 B
Names plz
Chaining methods
One common pattern in javascript is to chain methods to achieve a specific goal:
let title = 'Title: THE MATRIX '
.slice(6) // ' THE MATRIX '
.trim() // 'THE MATRIX'
.toLowerCase() // 'the matrix'
.replace(' ', '-') // 'the-matrix'
// Final result:
console.log(title) // 'the-matrix'
This is an example of a chaining 4 different methods to transform the original
string 'Title: THE MATRIX '
into 'the-matrix'
.
Instructions
It's now your turn to chain methods!
Declare a namePlz
function that takes an array of objects with a .name
string property and does:
.map
form objects to get only the propertyname
.join
each names with a,
and a space
Example:
const result = namePlz([
{ name: 'Wasan' },
{ name: 'Alanoud' },
{ name: 'Salama' },
{ name: 'Yousuf' },
{ name: 'Maitha' },
])
console.log(result) // 'Wasan, Alanoud, Salama, Yousuf, Maitha'