Skip to content

Instantly share code, notes, and snippets.

@garybunofsky
Created January 2, 2018 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garybunofsky/85a6604a6e9d25046d53afe5ae789e3e to your computer and use it in GitHub Desktop.
Save garybunofsky/85a6604a6e9d25046d53afe5ae789e3e to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/solepek
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
// Write a function called newCars
// that returns an array of cars
// newer than the year 2000.
var carList = [
{
make: 'chevy',
year: 1968
},
{
make: 'bmw',
year: 2012
},
{
make: 'toyota',
year: 1994
},
{
make: 'jeep',
year: 1999
},
{
make: 'jaguar',
year: 2015
},
{
make: 'nissan',
year: 2016
}
];
function newCars(carList) {
var newCars = [];
carList.forEach(function(car) {
if(car.year > 2000){
newCars.push(car);
}
});
return newCars;
}
console.log(newCars(carList));
</script>
<script id="jsbin-source-javascript" type="text/javascript">// Write a function called newCars
// that returns an array of cars
// newer than the year 2000.
var carList = [
{
make: 'chevy',
year: 1968
},
{
make: 'bmw',
year: 2012
},
{
make: 'toyota',
year: 1994
},
{
make: 'jeep',
year: 1999
},
{
make: 'jaguar',
year: 2015
},
{
make: 'nissan',
year: 2016
}
];
function newCars(carList) {
var newCars = [];
carList.forEach(function(car) {
if(car.year > 2000){
newCars.push(car);
}
});
return newCars;
}
console.log(newCars(carList));
</script></body>
</html>
// Write a function called newCars
// that returns an array of cars
// newer than the year 2000.
var carList = [
{
make: 'chevy',
year: 1968
},
{
make: 'bmw',
year: 2012
},
{
make: 'toyota',
year: 1994
},
{
make: 'jeep',
year: 1999
},
{
make: 'jaguar',
year: 2015
},
{
make: 'nissan',
year: 2016
}
];
function newCars(carList) {
var newCars = [];
carList.forEach(function(car) {
if(car.year > 2000){
newCars.push(car);
}
});
return newCars;
}
console.log(newCars(carList));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment