September 2017
Intermediate to advanced
216 pages
6h 8m
English
Let's revisit the earlier example where we mapped a list of names. We'll do the same thing here, except that we'll add the resulting string to each map as a new key-value pair:
const capitalize = s => `${s.charAt(0).toUpperCase()}${s.slice(1)}`;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 => v.set('name', [ capitalize(v.get('first')), capitalize(v.get('last')) ].join(' ')));console.log('myList', myList.toJS());// -> myList [ { first: 'joe', last: 'brown', age: 45 },// -> { first: 'john', last: 'smith', age: 32 },// -> { first: 'mary', last: 'wise', age: ...Read now
Unlock full access