Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

homework 4 #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions lab/lab1/part1.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,15 @@ Is printMenu a function? Answer this question with underscore. Should evaluate
to true.
===================== */

var query1;

var query1 = _.isFunction(printMenu);
console.log('printMenu is a function:', query1);

/* =====================
Is bakedGoods an array? Answer this question with underscore. Should evaluate
to true.
===================== */

var query2;
var query2 = _.isArray(bakedGoods);

console.log('bakedGoods is an array:', query2);

Expand All @@ -84,39 +83,38 @@ Is the first element in bakedGoods an object? Answer this question with
underscore. Should evaluate to true.
===================== */

var query3;
var query3 = _.isObject(bakedGoods[0]);

console.log('The first element in bakedGoods is an object:', query3);

/* =====================
Use _.where to return all cakes. Or bread. Whichever is your favorite.
===================== */

var query4;

var query4 = _.where(bakedGoods, {type: "Cake"});
console.log('All bread. Or cakes:', query4);

/* =====================
Use _.filter to return all baked goods that cost more than $4.
===================== */

var query5;
var query5 = _.filter(bakedGoods, function(g){return g.price > 4.0;});

console.log('More than $4:', query5);

/* =====================
Use _.sortBy to order the list by inventory (from lowest to highest).
===================== */

var query6;
var query6 = _.sortBy(bakedGoods, 'inventory');

console.log('Sorted by inventory (lowest to highest):', query6);

/* =====================
Use _.groupBy to organize the baked goods by type.
===================== */

var query7;
var query7 = _.groupBy(bakedGoods, 'type');

console.log('Grouped by type:', query7);

Expand Down
10 changes: 10 additions & 0 deletions lab/lab2/js/part1-ajax-calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ var Stamen_TonerLite = L.tileLayer('http://stamen-tiles-{s}.a.ssl.fastly.net/ton
maxZoom: 20,
ext: 'png'
}).addTo(map);

var promise = $.ajax('https://raw.githubusercontent.com/MUSA611-CPLN692-spring2020/datasets/master/json/philadelphia-bike-crashes-snippet.json');
promise.done(console.log); // this prints it in json form

var unparsed; // converting to csv
promise.done(x=> unparsed = x); // saving the json as a new variable 'unparsed'
parsed = JSON.parse(unparsed); // parsing 'unparsed'
console.log(parsed);

// $ means jquery
26 changes: 20 additions & 6 deletions lab/lab2/js/part2-app-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,31 @@
===================== */

// Use the data source URL from lab 1 in this 'ajax' function:
var downloadData = $.ajax("http://");
var downloadData = $.ajax("https://raw.githubusercontent.com/MUSA611-CPLN692-spring2020/datasets/master/json/philadelphia-bike-crashes-snippet.json");

// Write a function to prepare your data (clean it up, organize it
// as you like, create fields, etc)
var parseData = function() {};
var parseData = function(data){return parsed=JSON.parse(data)};

// Write a function to use your parsed data to create a bunch of
// marker objects (don't plot them!)
var makeMarkers = function() {};
var createMarkers = function(crash){
var lat = crash.lat_final;
var long = crash.long_final;
var marker = L.marker([lat,long]);
return marker;
};

var makeMarkers = function(parsedData) {
markers = _.map(parsedData, createMarkers);
return markers;
};

// Now we need a function that takes this collection of markers
// and puts them on the map
var plotMarkers = function() {};
var plotMarkers = function(markers) {
_.map(markers, function(m){m.addTo(map)});
};

// At this point you should see a bunch of markers on your map if
// things went well.
Expand All @@ -66,9 +78,11 @@ var plotMarkers = function() {};

// Look to the bottom of this file and try to reason about what this
// function should look like
var removeMarkers = function() {};
var removeMarkers = function(markers) {
_.map(markers, function(x){map.removeLayer(x)});
};

/* =====================
/* ==============2wsx=======
Optional, stretch goal
Write the necessary code (however you can) to plot a filtered down version of
the downloaded and parsed data.
Expand Down