map, filter & reduce
//ES6
let list = ['Bob', 'Tom', 'Geoffrey', 'Scotty'];
//Filter for names less than 7 chars long, make uppercase and put into object {id, name, length}
var nameArray = list.filter( x => x.length < 7 ) // [ 'Bob', 'Tom', 'Scotty' ]
.map( z => z.toUpperCase()) // [ 'BOB', 'TOM', 'SCOTTY' ]
.reduce( (current, next, i) => { // next is the next item in [ 'BOB', 'TOM', 'SCOTTY' ] staring at the beginning
current.push({
id: i,
name: next,
length: next.length
});
return current; // current will return when we have gone through each item in [ 'BOB', 'TOM', 'SCOTTY' ]
}, []); //[] is the 'current' starting item
console.log(nameArray);
INFO