You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+2-78
Original file line number
Diff line number
Diff line change
@@ -44,86 +44,10 @@ Solved enough to pass to next round. My two solutions worked flawlessly on the f
44
44
45
45
After the qualification, as practice, I solved problem 3, `Cryptopangrams`, inside the `cypher.js` file. Problem 4 is also solved in `datbae.js`, very tough problem!
46
46
47
-
### Motivation
48
-
49
-
The Code Jam competition only supports nodejs `4.8.2` which creates a barrier of entry for someone who's writing modern javascript on a daily basis. We are just very much used to the syntax sugar and new functionality available to us.
50
-
51
-
### How does it work?
47
+
### Transpiling
52
48
53
49
> CodeJam 2019 has enabled nodejs v11.13.0!
54
50
55
-
That means that transpiling is no longer vital, however, we may want special language features and babel can still provide that. For instance, pipe operators.
56
-
57
-
We setup babel as transpiler to help us convert our code to our target environment, that is, `4.8.2`.
58
-
59
-
```json
60
-
{
61
-
"presets": [
62
-
[
63
-
"@babel/preset-env",
64
-
{
65
-
"targets": {
66
-
"node": "4.8"
67
-
}
68
-
}
69
-
]
70
-
]
71
-
}
72
-
```
73
-
74
-
We install these dependencies:
75
-
76
-
```json
77
-
{
78
-
"devDependencies": {
79
-
"@babel/cli": "^7.2.3",
80
-
"@babel/core": "^7.2.2",
81
-
"@babel/node": "^7.2.2",
82
-
"@babel/preset-env": "^7.2.3"
83
-
}
84
-
}
85
-
```
86
-
87
-
And setup our scripts:
88
-
89
-
```json
90
-
{
91
-
"scripts": {
92
-
"start": "babel-node",
93
-
"transpile": "babel src -d build",
94
-
"test": "echo \"Error: no test specified\" && exit 1"
95
-
}
96
-
}
97
-
```
98
-
99
-
Just in case you want to use some new features to help you build test cases, you can use `babel-node` to the start script. Just run `yarn start <filename>`. Alternatively, `npx babel-node <filename>`.
100
-
101
-
We now have a project that supports babel 7+ and all of the JavaScript candy that comes with it. Furthermore, our project will rewrite our code to make sure that node `4.8.2` can run it!
102
-
103
-
### Approach
104
-
105
-
First solve the problem!
106
-
107
-
Second, write the code, in `src/<problemName>/index.js`.
108
-
109
-
Third, transpile it, `yarn transpile`. This command will actually transpile all of the files located in `src/`.
110
-
111
-
Now we have `4.8.2` friendly code, located in a newly created, `build/` folder.
112
-
113
-
You can switch to node `4.8.2` using `nvm` and give it a go.
114
-
115
-
This repo features a code runner, which is constantly being improved. The code runner, will take problem name as argument, look for a test file inside `tests` and a solution file inside `build/`.
116
-
117
-
Test files should be named `problemName.in`. I have left two, but please generate your own.
118
-
119
-
With the solution placed in build and your test, file you can run your solution:
120
-
121
-
```bash
122
-
node runner <problemName/>
123
-
```
124
-
125
-
And we can see if our solution is working as expected.
51
+
To use transpiling checkout the v1 tag.
126
52
127
-
### Submission
128
53
129
-
To submit your solution, just go to Code Jam's website, navigate to the problem and select `Load File`. Then submit `build/<problemName>`, or just copy paste its contents into the Code Jam text editor.
0 commit comments