var options = [
{ name: 'One', assigned: true },
{ name: 'Two', assigned: false },
{ name: 'Three', assigned: true },
];
var reduced = options.reduce(function(filtered, option) {
if (option.assigned) {
var someNewValue = { name: option.name, newProperty: 'Foo' }
filtered.push(someNewValue);
}
return filtered;
}, []);
document.getElementById('output').innerHTML = JSON.stringify(reduced);
<h1>Only assigned options</h1>
<pre id="output"> </pre>
const filteredList = watchList.map(movie => ({
title : movie['Title'],
rating: movie["imdbRating"]
})
).filter(movie => {
return parseFloat(movie.rating) >= 8.0;
})
const files = [ 'foo.txt ', '.bar', ' ', 'baz.foo' ];
const filePaths = files
.map(file => file.trim())
.filter(Boolean)
.map(fileName => `~/cool_app/${fileName}`);
// filePaths = [ '~/cool_app/foo.txt', '~/cool_app/.bar', '~/cool_app/baz.foo']
const files = [ 'foo.txt ', '.bar', ' ', 'baz.foo' ];
const filePaths = files.reduce((acc, file) => {
const fileName = file.trim();
if(fileName) {
const filePath = `~/cool_app/${fileName}`;
acc.push(filePath);
}
return acc;
}, []);
// filePaths = [ '~/cool_app/foo.txt', '~/cool_app/.bar', '~/cool_app/baz.foo']
// Only change code below this line
const filteredList = watchList
.filter(({ imdbRating }) => imdbRating >= 8.0)
.map(({ Title: title, imdbRating: rating }) => ({ title, rating }));
// Only change code above this line
console.log(filteredList);
const filteredList = watchList
.filter(movie => {
// return true it will keep the item
// return false it will reject the item
return parseFloat(movie.imdbRating) >= 8.0;
})
.map(movie => {
return {
title: movie.Title,
rating: movie.imdbRating
};
});