Skip to content

Commit d16ca8f

Browse files
committed
first commit
0 parents  commit d16ca8f

10 files changed

+50
-0
lines changed

a-f-and-this.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var foot = {
2+
kick: function () {
3+
this.yelp = "Ouch!";
4+
setImmediate(() => console.log(this.yelp));
5+
}
6+
};
7+
foot.kick();

arrow-function-p1.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
var inputs = process.argv.slice(2);
3+
var result = inputs.map(s => s[0])
4+
.reduce((soFar, s) => soFar + s);
5+
6+
console.log(`[${inputs}] becomes "${result}"`);

default-args-p1.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = (x=0, y=1) => (x+y) / 2;

default-args-p2.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = ( string, bangs = string.length ) => string + "!".repeat(bangs);

destruction.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let args = process.argv.slice(2);
2+
let result = {};
3+
4+
[, result.username, result.email] = args;
5+
6+
console.log(result);

hello-es6.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('HELLO ES6')

rest.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = (...args) => {
2+
var sum = args.reduce((soFar, value) => soFar + value, 0);
3+
return sum / args.length;
4+
}

spread.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var numbers = process.argv.slice(2);
2+
var min = Math.min(...numbers);
3+
4+
console.log(`The minimum of [${numbers}] is ${min}`);

tagged-template-string.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function html(pieces, ...substitutions) {
2+
var result = pieces[0]
3+
for (var i = 0; i < substitutions.length; i++) {
4+
result += escape(substitutions[i]) + pieces[i + 1];
5+
}
6+
7+
return result;
8+
}
9+
10+
function escape(s) {
11+
return s.replace(/&/g, "&amp;")
12+
.replace(/</g, "&lt;")
13+
.replace(/>/g, "&gt;")
14+
.replace(/'/g, "&apos;")
15+
.replace(/"/g, "&quot;");
16+
}
17+
18+
console.log(html`<b>${process.argv[2]} says</b>: "${process.argv[3]}"`)

template-string.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
console.log(`Hello, ${process.argv[2]}!
2+
Your name lowercased is "${process.argv[2].toLowerCase()}".`);

0 commit comments

Comments
 (0)