book

Report

As a team, answer all the questions the team's members submitted on our course forum. Each team member is responsible for one question. But everyone should work together to come up with a good solution. Your answer should consist of Lodash code and a brief writeup. Utilize _.map, _.filter, _.group ...etc. Do not use any for loop.

It is important for everyone to understand all the solutions and make sure you will be able to independently reproduce these solutions when asked to do so. Coming up, we will incorporate variations of these questions into a future hackathon and you are expected to be capable of reproducing and adapting your solutions.

Which course has the highest enrollment? by Andrew

//for course title
var group = _.groupBy(data, 'CourseTitle');
var coursesEnroll = _.mapValues(group, function(d){
   var enrollNumbers = _.pluck(d, 'N.ENROLL')
   return _.sum(enrollNumbers)
})
var max = _.max(coursesEnroll);
var bigClass =  _.pick(coursesEnroll, function(d){
   return d == max;
});
return bigClass

First-Year Writing and Rhetoric 3187

How many instructors have taught each subject? by Kari

var group = _.groupBy(data, "Subject")

var result = _.mapValues(group, function(n){
	var S = _.pluck(n, "Instructors")
	return _.size(_.uniq(_.flatten(_.map(S, function(x){
		return _.pluck(x,"name")
	}))))
})
return result

HIST 45
HONR 10
HUMN 13
IAFS 16
IPHY 34
LING 19
MATH 61
MCDB 32
BAKR 3
PHIL 48
PHYS 54
PSCI 47
NRSC 9
PSYC 47
WRTG 85
RLST 13
SLHS 28
SOCY 58
ARAB 3
PORT 2
SPAN 62
COMR 4
FARR 8
GSAP 2
INVS 5
PACS 2
SEWL 3
DNCE 31
THTR 31
WMST 14
ACCT 17
BADM 16
BCOR 23
BSLW 1
BUSM 5
CESR 5
ESBM 13
FNCE 16
INBU 3
MBAC 11
MBAX 26
MGMT 28
MKTG 20
REAL 3
EDUC 75
ASEN 38
CHEN 21
CSCI 34
AREN 18
CVEN 40
ECEN 37
EMEN 9
EHON 2
GEEN 44
EVEN 2
HUEN 11
MCEN 48
TLEN 19
ATLS 18
MUSM 5
RSEI 1
JOUR 52
LAWS 89
CONV 2
EMUS 19
MUEL 25
MUSC 50
PMUS 31
TMUS 1
AIRR 5
MILR 5
NAVR 6
CSVC 2
LDSP 9
NRLN 1
PRLC 3
ARCH 1
ENVD 35
ARTH 10
ARTS 40
CAMW 2
CWCV 1
LGBT 1
LIBB 3
CHIN 6
FRSI 1
HIND 1
JPNS 7
KREN 1
ANTH 23
APPM 28
ASTR 21
ARSC 20
ATOC 19
CHEM 34
CLAS 16
COMM 35
EBIO 35
ECON 48
ENGL 72
ENVS 16
ETHN 16
FILM 23
FREN 23
ITAL 9
GEOG 22
GEOL 30
GRMN 20
HEBR 3
RUSS 10
SCAN 2
SWED 1
LEAD 1

Does the instructors tends to give out higher grades if they teach more classes? or the reverse? by Ming

var graded = _.filter(data,function(d){
  return d.hasOwnProperty("AVG_GRD");
})


var smallData = _.map(graded, function(d){
  var avg_grd = d.AVG_GRD;
  var nameArr = _.pluck(d.Instructors, 'name');
  var objArray = _.map(nameArr, function(d){
    var obj = {name:d,AVG_GRD:avg_grd};
    return obj;
  })
  return objArray;
});

var groups = _.groupBy(_.flatten(smallData),'name');

var groups2 = _.map(groups, function(d){
  var avg = _.reduce(d, function(total,e){
    return total+e.AVG_GRD;
  },0)/_.size(d);
  var obj = {classcount:_.size(d),AVG_GRD:avg,name:_.first(d).name}
  return obj;
});
var groups3 = _.groupBy(groups2,'classcount');

var avgbyCount = _.mapValues(groups3, function(d){
  var avg = _.reduce(d, function(total,e){
    return total+e.AVG_GRD;
  },0)/_.size(d);
  var obj = {classcount:_.first(d).classcount,AVG_GRD:avg,instrCount:_.size(d)}
  return obj;
});
return avgbyCount

{
 "1": {
  "classcount": 1,
  "AVG_GRD": 3.282425000000004,
  "instrCount": 800
 },
 "2": {
  "classcount": 2,
  "AVG_GRD": 3.2711051829268296,
  "instrCount": 656
 },
 "3": {
  "classcount": 3,
  "AVG_GRD": 3.30401925391095,
  "instrCount": 277
 },
 "4": {
  "classcount": 4,
  "AVG_GRD": 3.213417266187052,
  "instrCount": 139
 },
 "5": {
  "classcount": 5,
  "AVG_GRD": 3.2277377049180327,
  "instrCount": 61
 },
 "6": {
  "classcount": 6,
  "AVG_GRD": 3.1722222222222216,
  "instrCount": 69
 },
 "7": {
  "classcount": 7,
  "AVG_GRD": 3.202216748768473,
  "instrCount": 29
 },
 "8": {
  "classcount": 8,
  "AVG_GRD": 3.10605,
  "instrCount": 25
 },
 "9": {
  "classcount": 9,
  "AVG_GRD": 3.5538095238095244,
  "instrCount": 7
 },
 "10": {
  "classcount": 10,
  "AVG_GRD": 2.717,
  "instrCount": 2
 },
 "14": {
  "classcount": 14,
  "AVG_GRD": 3.4803571428571427,
  "instrCount": 2
 },
 "15": {
  "classcount": 15,
  "AVG_GRD": 3.5316666666666663,
  "instrCount": 2
 },
 "16": {
  "classcount": 16,
  "AVG_GRD": 3.861875,
  "instrCount": 1
 },
 "20": {
  "classcount": 20,
  "AVG_GRD": 3.304500000000001,
  "instrCount": 1
 },
 "21": {
  "classcount": 21,
  "AVG_GRD": 2.5514285714285716,
  "instrCount": 1
 },
 "22": {
  "classcount": 22,
  "AVG_GRD": 3.185000000000001,
  "instrCount": 1
 },
 "25": {
  "classcount": 25,
  "AVG_GRD": 2.9128,
  "instrCount": 1
 },
 "26": {
  "classcount": 26,
  "AVG_GRD": 3.1234615384615387,
  "instrCount": 1
 },
 "27": {
  "classcount": 27,
  "AVG_GRD": 2.906296296296296,
  "instrCount": 1
 },
 "33": {
  "classcount": 33,
  "AVG_GRD": 2.695757575757576,
  "instrCount": 1
 },
 "39": {
  "classcount": 39,
  "AVG_GRD": 2.733589743589744,
  "instrCount": 1
 },
 "41": {
  "classcount": 41,
  "AVG_GRD": 2.599024390243903,
  "instrCount": 1
 },
 "60": {
  "classcount": 60,
  "AVG_GRD": 2.917166666666667,
  "instrCount": 1
 },
 "64": {
  "classcount": 64,
  "AVG_GRD": 2.375000000000001,
  "instrCount": 1
 }
}

Which department has the lowest enrollment? by John

var group = _.groupBy(data, "CrsPBADept")
var sum = _.mapValues(group, function(n){
	var enroll = _.pluck(n, "N.ENROLL")
	return _.sum(enroll)
})
var min = _.min(sum)
var result = _.pick(sum, function(x){
	return x == min
})
return result

RASE 30

Which subject is most in demand,based on the total number of enrollment? by Sussant

var group = _.groupBy(data, "Subject")
var sum = _.mapValues(group, function(n){
	var enroll = _.pluck(n, "N.ENROLL")
	return _.sum(enroll)
})
var max = _.max(sum)
var result = _.pick(sum, function(x){
	return x == max
})
return result

MATH 8725