Skip to content

Commit e691c40

Browse files
committed
fix es6 imports
1 parent 5dd1134 commit e691c40

File tree

17 files changed

+32
-132
lines changed

17 files changed

+32
-132
lines changed

‎README.md

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -415,51 +415,3 @@ Back to business.
415415
We have a suspect in mind: a classmate named "Hack Kerr". He's a nice guy, and he's always been friendly to you - but there's something suspicious about him: his name.
416416

417417
We'll test out flatten, then re-create our student array of data from the original course data.
418-
419-
##### reduce
420-
421-
Array -> anything
422-
423-
We know our likely suspect is also in the school computer system. Perhaps our suspect also changed his grades.
424-
425-
You can't be sure who is a cheater, but you can assume if the grades are well above the average, the person is likely to be the culprit. For this, we'll have to do some basic statistical calculations. We'll need a new tool for transforming arrays into different data representations.
426-
427-
`map` has a major limitation: it will always output the same number of elements as the input array.
428-
429-
When you want to transform data into something different, you'll likely want to use `reduce`.
430-
431-
Reduce requires two parameters:
432-
433-
* the running total (set by an initialValue)
434-
* the next value in the array
435-
436-
```js
437-
function add(total, next) {
438-
console.log(`add(${total}, ${next}) -> ${total + next}`)
439-
return total + next
440-
}
441-
442-
const initialValue = 100;
443-
[1, 5, 10].reduce(add, initialValue); // initial value
444-
445-
// add(100, 1) -> 101
446-
// add(101, 5) -> 106
447-
// add(106, 10) -> 116
448-
//> 116
449-
```
450-
451-
Notice in the example we input an array of 3 items and output a single number. The data has been transformed.
452-
453-
It takes a while to wrap your head around `reduce`, but once you do, you'll see it's usefulness everywhere.
454-
455-
You may have noticed we've already used `reduce` to `flatten` our arrays.
456-
457-
```js
458-
Array.prototype.flatten = function() {
459-
return this.reduce((a, b) => a.concat(b), []);
460-
};
461-
```
462-
463-
With `flatten`, the initialValue was set to an empty array which each value was `concat` onto.
464-
465-
Do some practice with `reduce`, before you use it to narrow down a cheating suspect.

‎coderoad.json

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
],
7373
"actions": [
7474
"open('01-filter.js')",
75-
"set('const students = require('./data/students').default;\n// Array.filter(fn)\n\nfunction isAda(student) {\n // return true if student name\n // matches \"Ada Lovelace\"\n ::>\n}\n')"
75+
"set('import students from './data/students';\n// Array.filter(fn)\n\nfunction isAda(student) {\n // return true if student name\n // matches \"Ada Lovelace\"\n ::>\n}\n')"
7676
],
7777
"hints": [
7878
"Some tasks have hints",
@@ -139,7 +139,7 @@
139139
],
140140
"actions": [
141141
"open('02-sort.js')",
142-
"set('const myBest = require('./data/myBest').default;\n// Array.sort(fn)\n\nfunction compareScore(a, b) {\n switch (true) {\n case b.score > a.score:\n // it should return 1 if b's score is more than a's\n return ::>\n case 'set condition here':\n // it should return -1 if b's score is less than a's\n\n default:\n // it should return 0 if b and a have the same score\n\n }\n}\n')"
142+
"set('import myBest from './data/myBest';\n// Array.sort(fn)\n\nfunction compareScore(a, b) {\n switch (true) {\n case b.score > a.score:\n // it should return 1 if b's score is more than a's\n return ::>\n case 'set condition here':\n // it should return -1 if b's score is less than a's\n\n default:\n // it should return 0 if b and a have the same score\n\n }\n}\n')"
143143
]
144144
},
145145
{
@@ -196,7 +196,7 @@
196196
],
197197
"actions": [
198198
"open('03-map.js')",
199-
"set('const myCourses = require('./data/myCourses').default;\n// Array.map(fn)\n\n/*\n * change any the `course.grade` into an 'A'\n *\n * for example:\n * changeGrade({ grade: 'F' }) === { grade: 'A' };\n*/\n\nfunction changeGrade(course) {\n ::>\n}\n\n')"
199+
"set('import myCourses from './data/myCourses';\n// Array.map(fn)\n\n/*\n * change any the `course.grade` into an 'A'\n *\n * for example:\n * changeGrade({ grade: 'F' }) === { grade: 'A' };\n*/\n\nfunction changeGrade(course) {\n ::>\n}\n\n')"
200200
],
201201
"hints": [
202202
"give `changeGrade` a parameter, call it \"course\"",
@@ -292,7 +292,7 @@
292292
],
293293
"actions": [
294294
"open('04-forEach.js')",
295-
"set('const myFixed = require('./data/myFixed').default;\n// Array.forEach(fn)\n\nfunction logCourse(course) {\n console.log(`${course.grade} ${course.score} ${course.title}`);\n}\n\n// log your grades to the console\nmyFixed.forEach(::>);\n')"
295+
"set('import myFixed from './data/myFixed';\n// Array.forEach(fn)\n\nfunction logCourse(course) {\n console.log(`${course.grade} ${course.score} ${course.title}`);\n}\n\n// log your grades to the console\nmyFixed.forEach(::>);\n')"
296296
],
297297
"hints": [
298298
"call `forEach` with `logCourse`"
@@ -357,7 +357,7 @@
357357
],
358358
"actions": [
359359
"open('05-find.js')",
360-
"set('const courses = require('./data/myCourses2');\n// Array.find(fn)\n\n// filter for the course title matching \"Web Security\"\nconst myClass = courses.filter(::>);\n')"
360+
"set('import courses from './data/myCourses2';\n// Array.find(fn)\n\n// filter for the course title matching \"Web Security\"\nconst myClass = courses.filter(::>);\n')"
361361
],
362362
"hints": [
363363
"create a `filter` function that takes a param `course`",
@@ -435,69 +435,15 @@
435435
]
436436
},
437437
{
438-
"description": "First, test out `flatten` on the `flattenedArray`",
438+
"description": "First, test out `flatten` on the `flattenedArray`\nArray -> anything\n\nWe know our likely suspect is also in the school computer system. Perhaps our suspect also changed his grades.\n\nYou can't be sure who is a cheater, but you can assume if the grades are well above the average, the person is likely to be the culprit. For this, we'll have to do some basic statistical calculations. We'll need a new tool for transforming arrays into different data representations.\n\n`map` has a major limitation: it will always output the same number of elements as the input array.\n\nWhen you want to transform data into something different, you'll likely want to use `reduce`.\n\nReduce requires two parameters:\n\n * the running total (set by an initialValue)\n * the next value in the array\n\n```js\nfunction add(total, next) {\n console.log(`add(${total}, ${next}) -> ${total + next}`)\n return total + next\n}\n\nconst initialValue = 100;\n[1, 5, 10].reduce(add, initialValue); // initial value\n\n// add(100, 1) -> 101\n// add(101, 5) -> 106\n// add(106, 10) -> 116\n//> 116\n```\n\nNotice in the example we input an array of 3 items and output a single number. The data has been transformed.\n\nIt takes a while to wrap your head around `reduce`, but once you do, you'll see it's usefulness everywhere.\n\nYou may have noticed we've already used `reduce` to `flatten` our arrays.\n\n```js\nArray.prototype.flatten = function() {\n return this.reduce((a, b) => a.concat(b), []);\n};\n```\n\nWith `flatten`, the initialValue was set to an empty array which each value was `concat` onto.\n\nDo some practice with `reduce`, before you use it to narrow down a cheating suspect.",
439439
"tests": [
440440
"06/02"
441441
],
442442
"actions": [
443443
"open('06-concat.js')",
444-
"set('const courses = require('./data/courses2').default;\n// Array.concat(any)\n\n// Array.prototype can be used to create new Array methods\nArray.prototype.flatten = function() {\n return this.reduce((a, b) => a.concat(b), []);\n};\n')",
445-
"insert('\nconst numberedList = [[1, 2], [3, 4]];\n\n// use `flatten` on `numberedList`\nconst flattenedArray = numberedList::>;\n')"
446-
],
447-
"hints": [
448-
"call `.flatten()` on `numberedList`"
449-
]
450-
},
451-
{
452-
"description": "Now `map` over the courses array, and `map` over the students array inside of it.\nReturn the fields:\n\n * title\n * instructor\n * name\n * grade\n * score",
453-
"tests": [
454-
"06/03"
455-
],
456-
"actions": [
457-
"insert('\n// map over courses then\n// map over students inside of courses\nconst doubleArray = courses.map((course) => {\n return course.students.map((student) => {\n return {\n // fill in the fields\n title: ::>'',\n instructor: '',\n name: '',\n score: '',\n grade: ''\n };\n });\n});\n\n')"
458-
],
459-
"hints": [
460-
"pair `course.title`",
461-
"pair `student.name`"
444+
"set('```\nimport courses from './data/courses2');\n// Array.concat(any)\n\n// Array.prototype can be used to create new Array methods\nArray.prototype.flatten = function() {\n return this.reduce((a, b) => a.concat(b), []);\n};\n```\n))\n@action(insert(\n```\n\nconst numberedList = [[1, 2], [3, 4]];\n\n// use `flatten` on `numberedList`\nconst flattenedArray = numberedList::>;\n``` \n))\n@hint('call `.flatten()` on `numberedList`')\n\n\n+ Now `map` over the courses array, and `map` over the students array inside of it.\nReturn the fields:\n\n * title\n * instructor\n * name\n * grade\n * score\n@test('06/03')\n@action(insert(\n```\n\n// map over courses then\n// map over students inside of courses\nconst doubleArray = courses.map((course) => {\n return course.students.map((student) => {\n return {\n // fill in the fields\n title: ::>'',\n instructor: '',\n name: '',\n score: '',\n grade: ''\n };\n });\n});\n\n```\n))\n@hint('pair `course.title`')\n@hint('pair `student.name`')\n\n+ Use `flatten` to put all data into a single array. Set `students` to the result.\n@test('06/04')\n@action(insert(\n```\n// `flatten` doubleArray\nconst students = doubleArray::>;\n```\n))\n@hint('call `.flatten()` on `doubleArray`')\n\n+ Use the `suspects` array to `filter` to only data matching the names in the `suspects` array\n@test('06/05')\n@action(insert(\n```\n\nconst suspects = [\"Hack Kerr\"];\n// filter to data matching `suspects`\n\nconst suspectData = students::>;\n```\n))\n\n+ You just thought of two more suspects! Make a new variable called `newSuspects` and add it above `suspects`.\n\n```js\nconst newSuspects = ['Albert Gonzalez', 'Kevin Mitnick'];\n```\n\n`concat` the `newSuspects` onto the `suspects` list.\n@test('06/06')\n@hint('call `suspects.concat()` with `newSuspects`')\n\n\n## redu')"
462445
]
463446
},
464-
{
465-
"description": "Use `flatten` to put all data into a single array. Set `students` to the result.",
466-
"tests": [
467-
"06/04"
468-
],
469-
"actions": [
470-
"insert('// `flatten` doubleArray\nconst students = doubleArray::>;\n')"
471-
],
472-
"hints": [
473-
"call `.flatten()` on `doubleArray`"
474-
]
475-
},
476-
{
477-
"description": "Use the `suspects` array to `filter` to only data matching the names in the `suspects` array",
478-
"tests": [
479-
"06/05"
480-
],
481-
"actions": [
482-
"insert('\nconst suspects = [\"Hack Kerr\"];\n// filter to data matching `suspects`\n\nconst suspectData = students::>;\n')"
483-
]
484-
},
485-
{
486-
"description": "You just thought of two more suspects! Make a new variable called `newSuspects` and add it above `suspects`.\n\n```js\nconst newSuspects = ['Albert Gonzalez', 'Kevin Mitnick'];\n```\n\n`concat` the `newSuspects` onto the `suspects` list.",
487-
"tests": [
488-
"06/06"
489-
],
490-
"hints": [
491-
"call `suspects.concat()` with `newSuspects`"
492-
]
493-
}
494-
],
495-
"onPageComplete": "In the next step, we'll look at using one of the most powerful methods: `reduce`"
496-
},
497-
{
498-
"title": "reduce",
499-
"description": "Array -> anything\n\nWe know our likely suspect is also in the school computer system. Perhaps our suspect also changed his grades.\n\nYou can't be sure who is a cheater, but you can assume if the grades are well above the average, the person is likely to be the culprit. For this, we'll have to do some basic statistical calculations. We'll need a new tool for transforming arrays into different data representations.\n\n`map` has a major limitation: it will always output the same number of elements as the input array.\n\nWhen you want to transform data into something different, you'll likely want to use `reduce`.\n\nReduce requires two parameters:\n\n * the running total (set by an initialValue)\n * the next value in the array\n\n```js\nfunction add(total, next) {\n console.log(`add(${total}, ${next}) -> ${total + next}`)\n return total + next\n}\n\nconst initialValue = 100;\n[1, 5, 10].reduce(add, initialValue); // initial value\n\n// add(100, 1) -> 101\n// add(101, 5) -> 106\n// add(106, 10) -> 116\n//> 116\n```\n\nNotice in the example we input an array of 3 items and output a single number. The data has been transformed.\n\nIt takes a while to wrap your head around `reduce`, but once you do, you'll see it's usefulness everywhere.\n\nYou may have noticed we've already used `reduce` to `flatten` our arrays.\n\n```js\nArray.prototype.flatten = function() {\n return this.reduce((a, b) => a.concat(b), []);\n};\n```\n\nWith `flatten`, the initialValue was set to an empty array which each value was `concat` onto.\n\nDo some practice with `reduce`, before you use it to narrow down a cheating suspect.",
500-
"tasks": [
501447
{
502448
"description": "load suspectData. We will come back to this after some practice;",
503449
"tests": [
@@ -515,7 +461,7 @@
515461
],
516462
"actions": [
517463
"open('07-reduce.js')",
518-
"set('const courses = require('./data/courses2');\n// Array.reduce(fn(a, b), initialValue)\n\nconst practice = [1, 1, 2, 3, 5, 8, 13, 21];\n\nfunction add(a, b) {\n return a + b;\n}\n\n// total the numbers using a reduce function\nconst total = practice.reduce(::>);\n')"
464+
"set('import courses from './data/courses2';\n// Array.reduce(fn(a, b), initialValue)\n\nconst practice = [1, 1, 2, 3, 5, 8, 13, 21];\n\nfunction add(a, b) {\n return a + b;\n}\n\n// total the numbers using a reduce function\nconst total = practice.reduce(::>);\n')"
519465
],
520466
"hints": [
521467
"with only numbers, the initialValue defaults to 0",
@@ -587,7 +533,8 @@
587533
"insert('console.log(likelySuspects);\n')"
588534
]
589535
}
590-
]
536+
],
537+
"onPageComplete": "In the next step, we'll look at using one of the most powerful methods: `reduce`"
591538
}
592539
]
593540
}

‎tutorial/01/01.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var expect = require('chai').expect;
22

3+
const students = require('BASE/data/students.js');
34
const filter = require('BASE/01-filter.js');
45

56
describe('01 function isAda', () => {

‎tutorial/01/filter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ console.log(students[0]);
5656
@action(open('01-filter.js'))
5757
@action(set(
5858
```
59-
const students = require('./data/students').default;
59+
import students from './data/students';
6060
// Array.filter(fn)
6161
6262
function isAda(student) {

‎tutorial/02/01.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const expect = require('chai').expect;
22

3-
describe('01 myBest data', () => {
3+
const myBest = require('BASE/data/myBest.js');
44

5-
const myBest = require('BASE/data/myBest.js');
5+
describe('01 myBest data', () => {
66

77
it('should be loaded in "data/myBest.js"', () => {
88
expect(myBest).to.not.be.undefined;

‎tutorial/02/sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ First you'll need to write a sort condition function called `compareScore`.
4242
@action(open('02-sort.js'))
4343
@action(set(
4444
```
45-
const myBest = require('./data/myBest').default;
45+
import myBest from './data/myBest';
4646
// Array.sort(fn)
4747
4848
function compareScore(a, b) {

‎tutorial/03/01.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const expect = require('chai').expect;
22

3-
describe('01 myCourses data', () => {
3+
const myCourses = require('BASE/data/myCourses.js');
44

5-
const myCourses = require('BASE/data/myCourses.js');
5+
describe('01 myCourses data', () => {
66

77
it('should be loaded in "data/myCourses.js"', () => {
88
expect(myCourses).to.not.be.undefined;

‎tutorial/03/map.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Let's go back to before we filtered out the bad grades, and instead change the g
6666
@action(open('03-map.js'))
6767
@action(set(
6868
```
69-
const myCourses = require('./data/myCourses').default;
69+
import myCourses from './data/myCourses';
7070
// Array.map(fn)
7171
7272
/*

‎tutorial/04/01.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ const spies = require('chai-spies');
33
const expect = chai.expect;
44
chai.use(spies);
55

6+
let myFixed = require('BASE/data/myFixed.js');
67
if (process.env.TASK_POSITION === '4') {
78
myFixed = [];
89
}
10+
911
let spy = chai.spy.on(console, 'log');
1012

1113
describe('01 myFixed data', () => {
1214

13-
const myFixed = require('BASE/data/myFixed.js');
14-
1515
it('should be loaded in "data/myFixed.js"', () => {
1616
expect(myFixed).to.not.be.undefined;
1717
});

‎tutorial/04/forEach.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Now that we see how `forEach` works, let's use it to make calls to the `console`
9696
@action(open('04-forEach.js'))
9797
@action(set(
9898
```
99-
const myFixed = require('./data/myFixed').default;
99+
import myFixed from './data/myFixed';
100100
// Array.forEach(fn)
101101
102102
function logCourse(course) {

‎tutorial/05/01.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const expect = require('chai').expect;
22

3-
describe('01 courses2 data', () => {
3+
const courses = require('BASE/data/courses2.js');
44

5-
const courses = require('BASE/data/courses2.js');
5+
describe('01 courses2 data', () => {
66

77
it('should be loaded in "data/courses2.js"', () => {
88
expect(courses).to.not.be.undefined;

‎tutorial/05/find.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Find is great for performantly matching unique values in data, such as an "id",
3535
@action(open('05-find.js'))
3636
@action(set(
3737
```
38-
const courses = require('./data/myCourses2');
38+
import courses from './data/myCourses2';
3939
// Array.find(fn)
4040
4141
// filter for the course title matching "Web Security"

‎tutorial/06/01.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const expect = require('chai').expect;
22

3-
describe('01 load courses', () => {
3+
const courses = require('BASE/data/courses2.js');
44

5-
const courses = require('BASE/data/courses2.js');
5+
describe('01 load courses', () => {
66

77
it('should be loaded in "data/courses2.js"', () => {
88
expect(courses).to.not.be.undefined;

‎tutorial/06/concat.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ We'll test out flatten, then re-create our student array of data from the origin
105105
@action(open('06-concat.js'))
106106
@action(set(
107107
```
108-
const courses = require('./data/courses2').default;
108+
import courses from './data/courses2');
109109
// Array.concat(any)
110110
111111
// Array.prototype can be used to create new Array methods

‎tutorial/07/01.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
describe('01 suspectData', () => {
1+
const expect = require('chai').expect;
2+
3+
const suspectData = require('BASE/data/suspectData.js');
24

3-
const suspectData = require('BASE/data/suspectData.js');
5+
describe('01 suspectData', () => {
46

57
it('should be loaded in "data/suspectData.js"', () => {
68
expect(suspectData).to.not.be.undefined;

‎tutorial/07/02.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = require('chai').expect;
2-
31
const reduce = require('BASE/07-reduce.js');
42

53
describe('02 const total', () => {

‎tutorial/07/reduce.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Do some practice with `reduce`, before you use it to narrow down a cheating susp
5555
@action(open('07-reduce.js'))
5656
@action(set(
5757
```
58-
const courses = require('./data/courses2');
58+
import courses from './data/courses2';
5959
// Array.reduce(fn(a, b), initialValue)
6060
6161
const practice = [1, 1, 2, 3, 5, 8, 13, 21];

0 commit comments

Comments
 (0)