forked from MUSA611-CPLN692-spring2019/cpln692-week3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
part1.js
executable file
·79 lines (50 loc) · 2.64 KB
/
part1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* =====================
# Lab 2, Part 1 — Underscore Selection
## Introduction
Set variables "query1" through "query8" by using an underscore function to answer the specified question. When you are finished, check your browser's console log to test the results.
For data, use the following two lists of board game collections.
===================== */
var rossGameList = ["catan", "hanabi", "code names", "chess", "candyland"];
console.log('ross\'s list', rossGameList);
var nathanGameList = ["chess", "dice", "catan", "pandemic"];
console.log('Nathan\'s list', nathanGameList);
/* =====================
What is the first game in Ross's list?
===================== */
var query1 = _.first(rossGameList);
console.log('What is the first game in Ross\'s list?', query1);
/* =====================
What are all of the games except for the first game in ross's list?
===================== */
var query2 = _.rest(rossGameList,[1]);
console.log('What are all of the games except for the first game in Ross\'s list?', query2);
/* =====================
What is the last game in Nathan's list?
===================== */
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= _.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= _.without(nathanGameList,'catan');
console.log('What would Nathan\'s game list look like if he sold "catan"?', query5);
/* =====================
If Nathan and Ross play a board game, what are their options? This should be a list of all games owned by ross or Nathan, with no duplicates.
===================== */
var query6 = _.union(rossGameList,nathanGameList);
console.log('If Nathan and Ross play a board game, what are their options? This should be a list of all games owned by ross or Nathan, with no duplicates.', query6);
/* =====================
Which games are owned by both Ross and Nathan?
===================== */
var query7 = _.intersection(rossGameList,nathanGameList);
console.log('Which games are owned by both Ross and Nathan', query7);
/* =====================
Which games are exclusive to collections? In other words, only owned by either Ross or Nathan.
===================== */
var query8 = _.difference(rossGameList,nathanGameList);
console.log('Which games are exclusive to one collection? In other words, only owned by either Ross or Nathan (but not both!).', query8);