September 2017
Intermediate to advanced
216 pages
6h 8m
English
You can pass iteratee functions to map() that compute new values. Let's implement a function that capitalizes the string that's passed to it:
const capitalize = s => `${s.charAt(0).toUpperCase()}${s.slice(1)}`;
This function will make the first character of any string uppercase. Let's use this as part of an iteratee function passed to map() to help generate a list of names:
const myList = List.of( Map.of('first', 'joe', 'last', 'brown', 'age', 45), Map.of('first', 'john', 'last', 'smith', 'age', 32), Map.of('first', 'mary', 'last', 'wise', 'age', 56));const myMappedList = myList.map( v => [ capitalize(v.get('first')), capitalize(v.get('last')) ].join(' '));console.log('myList', myList.toJS());// -> myList [ { first: 'joe', ...Read now
Unlock full access