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

Week 4 - Hartofelis #10

Open
wants to merge 1 commit 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: 8 additions & 8 deletions lab/lab1/part1.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ 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);

Expand All @@ -72,7 +72,7 @@ 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 @@ -81,39 +81,39 @@ Is the first element in bakedGoods an object? Answer this question with
underscore. Should evaluate to true.
===================== */

var query3;
var query3 = _.isObject(bakedGoods);

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': 'Bread'});

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, (obj) => {return obj.price > 4});

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 All @@ -137,7 +137,7 @@ Rye ... $5.09
Whole Wheat ... $4.49
===================== */

// printMenu(query7);
//printMenu(query7);

/* =====================
Stretch Goal:
Expand Down
22 changes: 18 additions & 4 deletions lab/lab2/js/part1-ajax-calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
This recipe, can be used by underscore's _.filter. It will return only words with
>=5 characters.
===================== */
var isLengthOfFiveOrMore = function(str) {};
var isLengthOfFiveOrMore = function(str) {
return str.length >= 5;
};



console.log("isLengthOfFiveOrMore success:",
_.isEqual(_.filter(['this', 'is','a', 'test', 'testing'], isLengthOfFiveOrMore), ['testing']));
Expand All @@ -30,15 +34,18 @@ console.log("isLengthOfFiveOrMore success:",
function you write along with underscore's _.each to log the double of every
number in the provided array.
===================== */
var logDouble = function(num) {};
var logDouble = function(num) {
return console.log(num * 2);
};
var theArray = [1, 5, 20, 100];

_.each(theArray, logDouble);

/* =====================
Given this already defined function, define fizzbuzzArray so that, when mapped
over, it will equal ['fizz', 'buzz', 'fizzbuzz'];
===================== */
var fizzbuzzArray = [];
var fizzbuzzArray = [3, 5, 15];
var fizzbuzzFunc = function(num) {
var str = '';
if (num % 3 === 0) { str = 'fizz'; }
Expand Down Expand Up @@ -94,7 +101,6 @@ var phillySolarInstallationDataUrl = "https://raw.githubusercontent.com/CPLN692-
var phillyCrimeDataUrl = "https://raw.githubusercontent.com/CPLN692-MUSA611/datasets/master/json/philadelphia-crime-snippet.json";
var phillyBikeCrashesDataUrl = "https://raw.githubusercontent.com/CPLN692-MUSA611/datasets/master/json/philadelphia-bike-crashes-snippet.json";


/* =====================
Data you grab through ajax is just text. You'll need to parse it as javascript
objects to really work with it. Use the function `JSON.parse` on the string you
Expand All @@ -110,6 +116,14 @@ var phillyBikeCrashesDataUrl = "https://raw.githubusercontent.com/CPLN692-MUSA61
dataset you've pulled down.
===================== */

$.ajax("https://raw.githubusercontent.com/CPLN692-MUSA611/datasets/master/json/philadelphia-solar-installations.json").done(function(ajaxResponseValue) {
var solarData = JSON.parse(ajaxResponseValue);
console.log(solarData);
_.forEach(solarData, function(obj) {
popupText = obj.name;
L.marker([obj.LAT, obj.LONG_]).bindPopup(popupText).addTo(map);
});
});

/* =====================
Leaflet setup - feel free to ignore this
Expand Down
33 changes: 28 additions & 5 deletions lab/lab2/js/part2-app-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,29 @@
===================== */

// We set this to HTTP to prevent 'CORS' issues
var downloadData = $.ajax("http://");
var parseData = function() {};
var makeMarkers = function() {};
var plotMarkers = function() {};
var downloadData = $.ajax("https://raw.githubusercontent.com/CPLN692-MUSA611/datasets/master/json/philadelphia-solar-installations.json");

var parseData = function(web) {
return JSON.parse(web);
};

var makeMarkers = function(solarData) {
var markers = [];
_.forEach(solarData, function(obj) {
markers.push(L.circleMarker([obj.LAT, obj.LONG_],{
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5,
radius: 15
}));
});
return markers;};

var plotMarkers = function(markers) {
_.forEach(markers, function(i){
i.addTo(map);
});
};


/* =====================
Expand All @@ -53,7 +72,11 @@ var plotMarkers = function() {};
user's input.
===================== */

var removeMarkers = function() {};
var removeMarkers = function(markers) {
_.forEach(markers, function(i){
map.removeLayer(i);
});
};

/* =====================
Optional, stretch goal
Expand Down
31 changes: 24 additions & 7 deletions lab/lab2/js/part3-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,46 @@
/* =====================
Define a resetMap function to remove markers from the map and clear the array of markers
===================== */
var resetMap = function() {
/* =====================
Fill out this function definition
===================== */
var resetMap = function () {
_.forEach(myMarkers, function(marker){
map.removeLayer(marker);
});
};

/* =====================
Define a getAndParseData function to grab our dataset through a jQuery.ajax call ($.ajax). It
will be called as soon as the application starts. Be sure to parse your data once you've pulled
it down!
===================== */
var getAndParseData = function() {

/* =====================
Fill out this function definition
===================== */
};
var phillySolarInstallationDataUrl = "https://raw.githubusercontent.com/CPLN692-MUSA611/datasets/master/json/philadelphia-solar-installations.json";

var getAndParseData = function() {
$.ajax(phillySolarInstallationDataUrl).done(function(ajaxResponseValue){
solarData = JSON.parse(ajaxResponseValue);
console.log(solarData);
}); };

/* =====================
Call our plotData function. It should plot all the markers that meet our criteria (whatever that
criteria happens to be — that's entirely up to you)
===================== */
var plotData = function() {

/* =====================
Fill out this function definition
===================== */
var plotData = function() {
_.each(solarData, function(obj){
var marker;
if (booleanField && obj.KW > 10) {
marker = L.marker([obj.LAT, obj.LONG_]).bindPopup(obj.NAME + ' -ZAP!').addTo(map);
}
if (obj.KW > numericField1 && obj.KW < numericField2) {
marker = L.marker([obj.LAT, obj.LONG_]).bindPopup(obj.NAME + ' -zap.').addTo(map);
}
myMarkers.push(marker);
});
};