Skip to content
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
2 changes: 1 addition & 1 deletion example/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
<script src="../data/phillySchools.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore.js"></script>
<script src="example.js"></script>
<script src="exampleLEO.js"></script>
</body>
</html>
8 changes: 4 additions & 4 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// Mock user input
// Filter out according to these zip codes:
var acceptedZipcodes = [19106, 19107, 19124, 19111, 19118];

// Filter according to enrollment that is greater than this variable:
var minEnrollment = 300;

Expand All @@ -23,10 +24,9 @@
for (var i = 0; i < schools.length - 1; i++) {
// If we have '19104 - 1234', splitting and taking the first (0th) element
// as an integer should yield a zip in the format above
if (typeof schools[i].ZIPCODE === 'string') {
var split = schools[i].ZIPCODE.split(' ');
var normalized_zip = parseInt(split[0]);
schools[i].ZIPCODE = normalized_zip;
{if (typeof schools[i].ZIPCODE === 'string')
{schools[i].ZIPCODE = schools[i].ZIPCODE.substring(0,5)
} else {schools[i].ZIPCODE = schools[i].ZIPCODE}
}

// Check out the use of typeof here — this was not a contrived example.
Expand Down
100 changes: 100 additions & 0 deletions example/exampleLEO.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
(function(){

var map = L.map('map', {
center: [39.9522, -75.1639],
zoom: 14
});
var Stamen_TonerLite = L.tileLayer('http://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}.{ext}', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
subdomains: 'abcd',
minZoom: 0,
maxZoom: 20,
ext: 'png'
}).addTo(map);

// Mock user input
// Filter out according to these zip codes:
var acceptedZipcodes = [19106, 19107, 19124, 19111, 19118];

// Filter according to enrollment that is greater than this variable:
var minEnrollment = 300;


// clean the data
for (var i = 0; i < schools.length - 1; i++) {
// If we have '19104 - 1234', splitting and taking the first (0th) element
// as an integer should yield a zip in the format above
{if (typeof schools[i].ZIPCODE === 'string')
{schools[i].ZIPCODE = schools[i].ZIPCODE.substring(0,5)
} else {schools[i].ZIPCODE = schools[i].ZIPCODE}
}

// Check out the use of typeof here — this was not a contrived example.
// Someone actually messed up the data entry.
if (typeof schools[i].GRADE_ORG === 'number') {
schools[i].HAS_KINDERGARTEN = schools[i].GRADE_LEVEL < 1;
schools[i].HAS_ELEMENTARY = 1 < schools[i].GRADE_LEVEL < 6;
schools[i].HAS_MIDDLE_SCHOOL = 5 < schools[i].GRADE_LEVEL < 9;
schools[i].HAS_HIGH_SCHOOL = 8 < schools[i].GRADE_LEVEL < 13;
} else {
schools[i].HAS_KINDERGARTEN = schools[i].GRADE_LEVEL.toUpperCase().indexOf('K') >= 0;
schools[i].HAS_ELEMENTARY = schools[i].GRADE_LEVEL.toUpperCase().indexOf('ELEM') >= 0;
schools[i].HAS_MIDDLE_SCHOOL = schools[i].GRADE_LEVEL.toUpperCase().indexOf('MID') >= 0;
schools[i].HAS_HIGH_SCHOOL = schools[i].GRADE_LEVEL.toUpperCase().indexOf('HIGH') >= 0;
}
}

// filter data
var filtered_data = [];
var filtered_out = [];
for (var i = 0; i < schools.length - 1; i++) {
// These really should be predicates!
isOpen = schools[i].ACTIVE.toUpperCase() == 'OPEN';
isPublic = (schools[i].TYPE.toUpperCase() !== 'CHARTER' ||
schools[i].TYPE.toUpperCase() !== 'PRIVATE');
isSchool = (schools[i].HAS_KINDERGARTEN ||
schools[i].HAS_ELEMENTARY ||
schools[i].HAS_MIDDLE_SCHOOL ||
schools[i].HAS_HIGH_SCHOOL);
meetsMinimumEnrollment = schools[i].ENROLLMENT > minEnrollment;
meetsZipCondition = acceptedZipcodes.indexOf(schools[i].ZIPCODE) >= 0;
filter_condition = (isOpen &&
isSchool &&
meetsMinimumEnrollment &&
!meetsZipCondition);

if (filter_condition) {
filtered_data.push(schools[i]);
} else {
filtered_out.push(schools[i]);
}
}
console.log('Included:', filtered_data.length);
console.log('Excluded:', filtered_out.length);

// main loop
var color;
for (var i = 0; i < filtered_data.length - 1; i++) {
isOpen = filtered_data[i].ACTIVE.toUpperCase() == 'OPEN';
isPublic = (filtered_data[i].TYPE.toUpperCase() !== 'CHARTER' ||
filtered_data[i].TYPE.toUpperCase() !== 'PRIVATE');
meetsMinimumEnrollment = filtered_data[i].ENROLLMENT > minEnrollment;

// Constructing the styling options for our map
if (filtered_data[i].HAS_HIGH_SCHOOL){
color = '#0000FF'; // blue
} else if (filtered_data[i].HAS_MIDDLE_SCHOOL) {
color = '#00FF00'; // green
} else {
color = '#FF0000'; //red
}

// The style options - note that we're using an object to define properties
var pathOpts = {'radius': filtered_data[i].ENROLLMENT / 30,
'fillColor': color};
L.circleMarker([filtered_data[i].Y, filtered_data[i].X], pathOpts)
.bindPopup(filtered_data[i].FACILNAME_LABEL)
.addTo(map);
}

})();
33 changes: 25 additions & 8 deletions lab/lab1/part1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Instructions: "Write a function that adds one to the number provided"
Example: "plusOne(2) should return 3"
===================== */

var plusOne = function() {};
var plusOne = function (num) {
return num + 1;
};

console.log('plusOne success:', plusOne(99) === 100);

Expand All @@ -17,16 +19,20 @@ Instructions: "Write a function, age, that takes a birth year and returns an age
Example: "age(2000) should return 18"
===================== */

var age = function(birth) {};
var age = function(birth) {
return 2020 - birth;
};

console.log('age success:', age(1971) === 46);
console.log('age success:', age(1971) === 49);

/* =====================
Instructions: "Write a function that returns true for numbers over 9000 and false otherwise"
Example: "over9000(22) should return false"
===================== */

var over9000 = function() {};
var over9000 = function(num) {
return num > 9000
};

console.log('over9000 success:', over9000(9001) === true && over9000(12) === false);

Expand All @@ -35,7 +41,9 @@ Instructions: "Write a function that returns the value of an object at a specifi
Example: "valueAtKey({'name': 'Nathan'}, 'name') should return 'Nathan'"
===================== */

var valueAtKey = function() {};
var valueAtKey = function(obj, keyx) {
return obj[keyx];
};

console.log('valueAtKey success:', valueAtKey({'foo': 'bar'}, 'foo') === 'bar');

Expand All @@ -45,7 +53,9 @@ Example: "y(0, 0, 0) should return 0; y(1, 1, 1) should return 2"
Remember: The standard mathematical expression for such a function is y=mx+b
===================== */

var y = function() {};
var y = function(m, x, b) {
return m*x + b
};

console.log('y success:', y(12, 1, 12) === 24);

Expand All @@ -54,7 +64,14 @@ Instructions: "Write a function which counts the number of times a value occurs
Example: "countItem(['a', 'b', 'a'], 'a') should return 2"
===================== */

var countItem = function() {};
var countItem = function(arr, val) {
countval = 0;
for (let i = 0; i < arr.length; i++) {
if (arr[i] == val) {
let countval = countval + 1
}
}
return countval.length;
};

console.log('countItem success:', countItem([1, 2, 3, 4, 5, 4, 4], 4) === 3);

41 changes: 31 additions & 10 deletions lab/lab1/part2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ Functions that `return` can be passed as values to other functions. Each exercis
Instructions: Write a function that *always* returns the number 1.
===================== */

var justOne = function() {};
var justOne = function() {
return 1
};

console.log('justOne success:', justOne() === 1);

/* =====================
Instructions: Write a function that returns true if a number is even.
===================== */

var isEven = function() {};
var isEven = function(num) {
return num%2 === 0;
};

console.log('isEven success:', isEven(2) === true && isEven(3) === false);

Expand All @@ -24,15 +28,24 @@ Instructions: Write a function that *always* returns false.
Use functions "justOne" and "isEven" somehow in the definition.
===================== */

var justFalse = function() {};
var justFalse = function() {
let num = justOne();
return isEven(num);
};

console.log('justFalse success:', justFalse() === false);

/* =====================
Instructions: Write a function that takes a boolean value and returns its opposite.
===================== */

var not = function() {};
var not = function(bool) {
if (bool === true) {
return false;
} else {
return true
}
};

console.log('not success:', not(true) === false);

Expand All @@ -41,20 +54,29 @@ Instructions: Write a function that returns true if a number is odd
Use functions "isEven" and "not" somehow in the definition.
===================== */

var isOdd = function() {};
var isOdd = function(num) {
let x = isEven(num);
return not(x);
};

console.log('isOdd success:', isOdd(4) === false);

/* =====================
Instructions: Write a function that takes a list of numbers and returns a list with only numbers above 10
===================== */

var filterOutLessThan10 = function() {};
var filterOutLessThan10 = function(num) {
._filter(num, function(num) { return num > 10; })
};
// The function 'arraysEqual' (which it is your task to define) is necessary because
// ([4] === [4]) is *false* in javascript(!!!)
// Use google + stackoverflow to figure out how to define a function which returns true given two equal arrays
function arraysEqual(arr1, arr2) { return false; }
console.log('filterOutLessThan10 success:', arraysEqual([4, 11], [11]));
function arraysEqual(arr1, arr2) {
if (JSON.stringify(arr1) !== JSON.stringify(arr2)) {
return false;
}
}
console.log('filterOutLessThan10 success:', arraysEqual(filterOutLessThan10([4, 11]), [11]));

/* =====================
Stretch goal
Expand All @@ -65,5 +87,4 @@ Instructions: Let's bring it all together. Write a function that filters a list

var filter = function(array, func) {};

console.log('filter success:', filter([4, 11], isOdd) === [11]);

console.log('filter success:', arraysEqual(filter([4, 11], isOdd), [11]));
16 changes: 8 additions & 8 deletions lab/lab2/part1.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,62 +19,62 @@ console.log('Nathan\'s list', nathanGameList);
What is the first game in Jeff's list?
===================== */

var query1;
var query1 = _.first(jeffGameList);

console.log('What is the first game in Jeff\'s list?', query1);

/* =====================
What are all of the games except for the first game in Jeff's list?
===================== */

var query2;
var query2 = _.rest(jeffGameList, [1]);

console.log('What are all of the games except for the first game in Jeff\'s list?', query2);

/* =====================
What is the last game in Nathan's list?
===================== */

var query3;
var query3 = _.last(nathanGameList);

console.log('What is the last game in Nathan\'s list?', query3);

/* =====================
What are all of the games in Nathan's list except for the last?
===================== */

var query4;
var query4 = _.initial(nathanGameList);

console.log('What are all of the games in Nathan\'s list except for the last?', query4);

/* =====================
What would Nathan's game list look like if he sold "catan"?
===================== */

var query5;
var query5 = _.without(nathanGameList, "catan");

console.log('What would Nathan\'s game list look like if he sold "catan"?', query5);

/* =====================
If Nathan and Jeff play a board game, what are their options? This should be a list of all games owned by Jeff or Nathan, with no duplicates.
===================== */

var query6;
var query6 = _.union(nathanGameList, jeffGameList);

console.log('If Nathan and Jeff play a board game, what are their options? This should be a list of all games owned by Jeff or Nathan, with no duplicates.', query6);

/* =====================
Which games are owned by both Jeff and Nathan?
===================== */

var query7;
var query7 = _.intersection(nathanGameList, jeffGameList);

console.log('Which games are owned by both Jeff and Nathan', query7);

/* =====================
Which games are exclusive to collections? In other words, only owned by either Jeff or Nathan.
===================== */

var query8;
var query8 = _.union(_.difference(nathanGameList, jeffGameList), _.difference(jeffGameList, nathanGameList));

console.log('Which games are exclusive to one collection? In other words, only owned by either Jeff or Nathan (but not both!).', query8);
6 changes: 4 additions & 2 deletions lab/lab2/part2.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Calculate the value by using _.countBy and set your answer to variable "largeSta

var data = bikeArrayClean;

var largeStationList;
var largeStationList = _.filter(data, function(num) {return num [3] > 20});
console.log(largeStationList);

var largeStationCount;
var largeStationCount = _.countBy(data, function(num) {return num [3] > 20});
console.log(largeStationCount);