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

HW4 #4

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
39 changes: 30 additions & 9 deletions lab/lab1/part1.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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 @@ -75,7 +75,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 @@ -84,39 +84,40 @@ 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 = _.filter(bakedGoods,function(x){return _.isMatch(x, {"type": "Cake"})})
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(i){return i.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 @@ -140,8 +141,15 @@ Rye ... $5.09
Whole Wheat ... $4.49

===================== */
var printMenu2 = function(foodList){
for (i = 0; i < Object.keys(foodList).length; i++){
console.log(Object.keys(foodList)[i]);
printMenu(Object.values(foodList)[i])
}
};

printMenu2(query7);

// printMenu2(query7);

/* =====================
Stretch Goal (seriously, this is a bit tough at first!):
Expand All @@ -155,7 +163,20 @@ rendering process.
Use _.template to render the price lines of the menu (Carrot ... $3.49).

Hint: Pay close attention to the example provided in documentation. Copy and paste
it so that you can try it out for yourself. Once you think youunderstand how it
it so that you can try it out for yourself. Once you think you understand how it
works, give it a try.

===================== */
var printMenu = function(foodList) {
_.each(foodList, function(food) {
console.log(food.name + ' ... $' + food.price);
});
};

var compiled = _.template("<% print('Hello ' + epithet); %>");
compiled({epithet: "stooge"});

var printMenu3 = function(foodList){
var compiled = _.template("<% print(name + ' ... $' + price); %>");
return compiled(foodList)
}
9 changes: 9 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,12 @@ var Stamen_TonerLite = L.tileLayer('http://stamen-tiles-{s}.a.ssl.fastly.net/ton
maxZoom: 20,
ext: 'png'
}).addTo(map);

/*
mypromise = $.ajax('https://raw.githubusercontent.com/MUSA611-CPLN692-spring2020/datasets/master/json/philadelphia-crime-snippet.json')
var dataCollector=[];
mypromise.done(function(x){dataCollector=x});
console.log(dataCollector)
*/

$.ajax('https://raw.githubusercontent.com/MUSA611-CPLN692-spring2020/datasets/master/json/philadelphia-crime-snippet.json').done(function(x){console.log(x)})
41 changes: 36 additions & 5 deletions lab/lab2/js/part2-app-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,37 @@
===================== */

// 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-crime-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(response) {var parseOne= JSON.parse(response);
var holder =[];
holder[0] = Object.keys(parseOne[0]);
for (i=0; i<parseOne.length; i++) {
holder[i+1]=Object.values(parseOne[i]);
}
return holder
};

// Write a function to use your parsed data to create a bunch of
// marker objects (don't plot them!)
var makeMarkers = function() {};

var makeMarkers = function(marker){
var holder2 =[];
for (i=1; i< marker.length; i++){
holder2[i-1] = L.marker([marker[i][7],marker[i][8]])
}
return holder2
};

// Now we need a function that takes this collection of markers
// and puts them on the map
var plotMarkers = function() {};
var plotMarkers = function(plot) {
for (i=0; i< plot.length; i++){
plot[i].addTo(map)//why if i use return plot[1].addTo(map), only the last marker was returned to the map?
}
};

// At this point you should see a bunch of markers on your map if
// things went well.
Expand All @@ -66,7 +84,20 @@ 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(points) {
for (i = 0; i< points.length; i++){
map.removeLayer(points[i])
}
};
*/

var removeMarkers = function(points) {
_.each(points,function(point){
map.removeLayer(point)
})
};


/* =====================
Optional, stretch goal
Expand Down