Skip to content

Commit 16e014a

Browse files
committed
change relative imports to require to avoid import bug
1 parent f5cd218 commit 16e014a

File tree

12 files changed

+31
-36
lines changed

12 files changed

+31
-36
lines changed

README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ Keywords: javascript, functional
99
Length: 1-2 hours
1010

1111

12-
<!-- @import('08/challenge-1') -->
13-
<!-- @import('09/challenge-2') -->
14-
15-
1612
## CodeRoad
1713

1814
CodeRoad is an open-sourced interactive tutorial platform for the Atom Editor. Learn more at [CodeRoad.io](http://coderoad.io).
@@ -67,7 +63,7 @@ It would be great if you could `filter` the scores that your parents will see.
6763

6864
`filter` takes a matching condition function and only returns items that result in true. As an example, look at `isA` below:
6965

70-
```
66+
```js
7167
function isA(x) {
7268
return x === 'a';
7369
}
@@ -76,7 +72,7 @@ function isA(x) {
7672

7773
Like all of the methods in this chapter, `filter` is already part of the `Array.prototype`, so you can run it following any array. Each item in the array is passed into the params of the condition function, one by one. [Learn more](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter).
7874

79-
```
75+
```js
8076
const list = ['a', 'b'];
8177
list.filter(isA);
8278

@@ -88,7 +84,7 @@ list.filter(isA);
8884

8985
If your data was composed of objects, we could use dot notation to find matches. Checkout `isB` below.
9086

91-
```
87+
```js
9288
function isB(x) {
9389
return x.item === 'b'
9490
}
@@ -102,7 +98,7 @@ Where were we? Back to filtering our grades.
10298

10399
There's too much student data in the computer system. We'll have to sort through it. Have a look at an example below:
104100

105-
```
101+
```js
106102
console.log(students[0]);
107103
//> { course: 'Web Security',
108104
// instructor: 'Sue Denim',
@@ -304,7 +300,7 @@ You quickly put together a list of other students in class. If someone changed y
304300

305301
`find` works similar to `filter`, but returns only the first match.
306302

307-
```
303+
```js
308304
const data = [1, 2, 3, 4, 5, 6];
309305

310306
function isEven(num) {

coderoad.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"info": {
33
"title": "Functional School",
4-
"description": "A trip through functional programming in Javascript using common built-in Javascript array methods such as `map` & `reduce`.\n\nBy the end, you should have an understanding of how to use array methods to manipulate semi-complex data.\n\nLevel: Intermediate\nKeywords: javascript, functional\nLength: 1-2 hours\n\n\n<!-- @import('08/challenge-1') -->\n<!-- @import('09/challenge-2') -->"
4+
"description": "A trip through functional programming in Javascript using common built-in Javascript array methods such as `map` & `reduce`.\n\nBy the end, you should have an understanding of how to use array methods to manipulate semi-complex data.\n\nLevel: Intermediate\nKeywords: javascript, functional\nLength: 1-2 hours"
55
},
66
"pages": [
77
{
@@ -25,7 +25,7 @@
2525
],
2626
"actions": [
2727
"open('00-setup.js')",
28-
"set('// Welcome to CodeRoad!\nimport students from './data/students';\n\nvar first = ::>\n')"
28+
"set('// Welcome to CodeRoad!\nconst students = require('./data/students').default;\n\nvar first = ::>\n')"
2929
],
3030
"hints": [
3131
"Get the first item in students using the array index",
@@ -64,7 +64,7 @@
6464
},
6565
{
6666
"title": "Filter",
67-
"description": "Array -> Array of items that match a condition\n\nYou've hacked into the school's computer system, and just in time. The grades are in, but you're not too proud of your performance. That's okay, you have a plan: you're going to create a fake report card.\n\nIt would be great if you could `filter` the scores that your parents will see.\n\n`filter` takes a matching condition function and only returns items that result in true. As an example, look at `isA` below:\n\n```\nfunction isA(x) {\n return x === 'a';\n}\n```\n\n\nLike all of the methods in this chapter, `filter` is already part of the `Array.prototype`, so you can run it following any array. Each item in the array is passed into the params of the condition function, one by one. [Learn more](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter).\n\n```\nconst list = ['a', 'b'];\nlist.filter(isA);\n\n// if isA(list[0]), add to output array\n// if isA(list[1]), add to output array\n//\n//> ['a']\n```\n\nIf your data was composed of objects, we could use dot notation to find matches. Checkout `isB` below.\n\n```\nfunction isB(x) {\n return x.item === 'b'\n}\n\nconst list = [{item: 'a'}, {item: 'b'}];\nlist.filter(isB);\n//> [{item: 'b'}]\n```\n\nWhere were we? Back to filtering our grades.\n\nThere's too much student data in the computer system. We'll have to sort through it. Have a look at an example below:\n\n```\nconsole.log(students[0]);\n//> { course: 'Web Security',\n// instructor: 'Sue Denim',\n// name: 'Rebecca Heineman',\n// score: 93,\n// grade: 'A' }\n```",
67+
"description": "Array -> Array of items that match a condition\n\nYou've hacked into the school's computer system, and just in time. The grades are in, but you're not too proud of your performance. That's okay, you have a plan: you're going to create a fake report card.\n\nIt would be great if you could `filter` the scores that your parents will see.\n\n`filter` takes a matching condition function and only returns items that result in true. As an example, look at `isA` below:\n\n```js\nfunction isA(x) {\n return x === 'a';\n}\n```\n\n\nLike all of the methods in this chapter, `filter` is already part of the `Array.prototype`, so you can run it following any array. Each item in the array is passed into the params of the condition function, one by one. [Learn more](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter).\n\n```js\nconst list = ['a', 'b'];\nlist.filter(isA);\n\n// if isA(list[0]), add to output array\n// if isA(list[1]), add to output array\n//\n//> ['a']\n```\n\nIf your data was composed of objects, we could use dot notation to find matches. Checkout `isB` below.\n\n```js\nfunction isB(x) {\n return x.item === 'b'\n}\n\nconst list = [{item: 'a'}, {item: 'b'}];\nlist.filter(isB);\n//> [{item: 'b'}]\n```\n\nWhere were we? Back to filtering our grades.\n\nThere's too much student data in the computer system. We'll have to sort through it. Have a look at an example below:\n\n```js\nconsole.log(students[0]);\n//> { course: 'Web Security',\n// instructor: 'Sue Denim',\n// name: 'Rebecca Heineman',\n// score: 93,\n// grade: 'A' }\n```",
6868
"tasks": [
6969
{
7070
"description": "Write a filter condition function called `isAda` that returns true only if the name matches your name: \"Ada Lovelace\".",
@@ -73,7 +73,7 @@
7373
],
7474
"actions": [
7575
"open('01-filter.js')",
76-
"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')"
76+
"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')"
7777
],
7878
"hints": [
7979
"Some tasks have hints",
@@ -141,7 +141,7 @@
141141
],
142142
"actions": [
143143
"open('02-sort.js')",
144-
"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')"
144+
"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')"
145145
]
146146
},
147147
{
@@ -198,7 +198,7 @@
198198
],
199199
"actions": [
200200
"open('03-map.js')",
201-
"set('import myCourses from './data/myCourses';\n// Array.map(fn)\n\n/*\n change any `course.grade`'s into an 'A'\n\n example:\n changeGrade({ grade: 'F' }) === { grade: 'A' };\n*/\nfunction changeGrade(course) {\n ::>\n}\n\n')"
201+
"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')"
202202
],
203203
"hints": [
204204
"give `changeGrade` a parameter, call it \"course\"",
@@ -294,7 +294,7 @@
294294
],
295295
"actions": [
296296
"open('04-forEach.js')",
297-
"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')"
297+
"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')"
298298
],
299299
"hints": [
300300
"call `forEach` with `logCourse`"
@@ -340,7 +340,7 @@
340340
},
341341
{
342342
"title": "find",
343-
"description": "Array -> first element that matches a condition\n\nSomehow your name has disappeared from the computer system. We'll have to `find` a way to get it back.\n\nYou quickly put together a list of other students in class. If someone changed your name, it'll be the name that is not in that list.\n\n`find` works similar to `filter`, but returns only the first match.\n\n```\nconst data = [1, 2, 3, 4, 5, 6];\n\nfunction isEven(num) {\n return num % 2 === 0;\n}\n\n// returns all matching data to a condition\ndata.filter(isEven);\n//> [2, 4, 6]\n\n// returns the first match\ndata.find(isEven);\n//> [2]\n```\n\nFind is great for performantly matching unique values in data, such as an \"id\", or in our case: a name.",
343+
"description": "Array -> first element that matches a condition\n\nSomehow your name has disappeared from the computer system. We'll have to `find` a way to get it back.\n\nYou quickly put together a list of other students in class. If someone changed your name, it'll be the name that is not in that list.\n\n`find` works similar to `filter`, but returns only the first match.\n\n```js\nconst data = [1, 2, 3, 4, 5, 6];\n\nfunction isEven(num) {\n return num % 2 === 0;\n}\n\n// returns all matching data to a condition\ndata.filter(isEven);\n//> [2, 4, 6]\n\n// returns the first match\ndata.find(isEven);\n//> [2]\n```\n\nFind is great for performantly matching unique values in data, such as an \"id\", or in our case: a name.",
344344
"tasks": [
345345
{
346346
"description": "load \"students\" data",
@@ -359,7 +359,7 @@
359359
],
360360
"actions": [
361361
"open('05-find.js')",
362-
"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')"
362+
"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')"
363363
],
364364
"hints": [
365365
"create a `filter` function that takes a param `course`",
@@ -443,7 +443,7 @@
443443
],
444444
"actions": [
445445
"open('06-concat.js')",
446-
"set('import 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')",
446+
"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')",
447447
"insert('\nconst numberedList = [[1, 2], [3, 4]];\n\n// use `flatten` on `numberedList`\nconst flattenedArray = numberedList::>;\n')"
448448
],
449449
"hints": [
@@ -517,7 +517,7 @@
517517
],
518518
"actions": [
519519
"open('07-reduce.js')",
520-
"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')"
520+
"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')"
521521
],
522522
"hints": [
523523
"with only numbers, the initialValue defaults to 0",

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coderoad-functional-school",
3-
"version": "0.6.1",
3+
"version": "1.0.0",
44
"description": "Coderoad tutorial",
55
"author": "Shawn McKay <shawn.j.mckay@gmail.com> (http://shmck.com)",
66
"contributers": [
@@ -22,7 +22,7 @@
2222
"url": "https://github.com/coderoad/coderoad-functional-school/issues"
2323
},
2424
"engines": {
25-
"node" : ">=0.10.3"
25+
"node" : ">=4.0.0"
2626
},
2727
"dependencies": {
2828
"chai": "3.5.0",

tutorial/00/setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ export default students;
10021002
@action(set(
10031003
```
10041004
// Welcome to CodeRoad!
1005-
import students from './data/students';
1005+
const students = require('./data/students').default;
10061006
10071007
var first = ::>
10081008
```

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-
import students from './data/students';
59+
const students = require('./data/students').default;
6060
// Array.filter(fn)
6161
6262
function isAda(student) {

tutorial/02/sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default myBest;
8989
@action(open('02-sort.js'))
9090
@action(set(
9191
```
92-
import myBest from './data/myBest';
92+
const myBest = require('./data/myBest').default;
9393
// Array.sort(fn)
9494
9595
function compareScore(a, b) {

tutorial/03/map.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,16 @@ export default myCourses;
131131
@action(open('03-map.js'))
132132
@action(set(
133133
```
134-
import myCourses from './data/myCourses';
134+
const myCourses = require('./data/myCourses').default;
135135
// Array.map(fn)
136136
137137
/*
138-
change any `course.grade`'s into an 'A'
139-
140-
example:
141-
changeGrade({ grade: 'F' }) === { grade: 'A' };
138+
* change any the `course.grade` into an 'A'
139+
*
140+
* for example:
141+
* changeGrade({ grade: 'F' }) === { grade: 'A' };
142142
*/
143+
143144
function changeGrade(course) {
144145
::>
145146
}

tutorial/04/forEach.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export default myFixed;
161161
@action(open('04-forEach.js'))
162162
@action(set(
163163
```
164-
import myFixed from './data/myFixed';
164+
const myFixed = require('./data/myFixed').default;
165165
// Array.forEach(fn)
166166
167167
function logCourse(course) {

tutorial/05/find.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ export default myCourses;
10001000
@action(open('05-find.js'))
10011001
@action(set(
10021002
```
1003-
import courses from './data/myCourses2';
1003+
const courses = require('./data/myCourses2');
10041004
// Array.find(fn)
10051005
10061006
// filter for the course title matching "Web Security"

tutorial/06/concat.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ export default courses;
790790
@action(open('06-concat.js'))
791791
@action(set(
792792
```
793-
import courses from './data/courses2';
793+
const courses = require('./data/courses2').default;
794794
// Array.concat(any)
795795
796796
// Array.prototype can be used to create new Array methods

tutorial/07/reduce.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export default suspectData;
240240
@action(open('07-reduce.js'))
241241
@action(set(
242242
```
243-
import courses from './data/courses2';
243+
const courses = require('./data/courses2');
244244
// Array.reduce(fn(a, b), initialValue)
245245
246246
const practice = [1, 1, 2, 3, 5, 8, 13, 21];

tutorial/tutorial.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,3 @@ Length: 1-2 hours
1616
@import('05/find')
1717
@import('06/concat')
1818
@import('07/reduce')
19-
<!-- @import('08/challenge-1') -->
20-
<!-- @import('09/challenge-2') -->

0 commit comments

Comments
 (0)