Last active
April 13, 2016 11:05
-
-
Save ama-ch/97def7765fb242d49709960c24644577 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var inputs = process.argv.slice(2); | |
var result = inputs.map((x) => x[0]).reduce((result, x) => result += x); | |
console.log(result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arg = process.argv[2]; | |
console.log(`Hello ${arg}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
let a = 5; | |
const b = process.argv[2]; | |
if (a === 5) { | |
let c = 4; | |
console.log(c); // 4 | |
const b = 8; | |
console.log(b); | |
} | |
console.log(a); // 5 | |
console.log(b); | |
try { | |
c = 1000; | |
} catch (e) { | |
console.log(e); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Character { | |
constructor(x, y) { | |
this.x = x; | |
this.y = y; | |
this.health_ = 100; | |
} | |
damage() { | |
this.health_ -= 10; | |
} | |
getHealth() { | |
return this.health_; | |
} | |
toString() { | |
return "x: " + this.x + " y: " + this.y + " health: " + this.health_; | |
} | |
} | |
var x = process.argv[2]; | |
var y = process.argv[3]; | |
var character = new Character(+x, +y); | |
character.damage(); | |
console.log(character.toString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
class Character { | |
constructor(x, y) { | |
this.x = x; | |
this.y = y; | |
this.health_ = 100; | |
} | |
damage() { | |
this.health_ -= 10; | |
} | |
getHealth() { | |
return this.health_; | |
} | |
toString() { | |
return "x: " + this.x + " y: " + this.y + " health: " + this.health_; | |
} | |
} | |
class Player extends Character { | |
constructor(x, y, name) { | |
super(x, y); | |
this.name = name; | |
} | |
move(dx, dy) { | |
this.x += dx; | |
this.y += dy; | |
} | |
toString() { | |
return "name: " + this.name + " " + super.toString(); | |
} | |
} | |
var x = process.argv[2]; | |
var y = process.argv[3]; | |
var name = process.argv[4]; | |
var character = new Character(+x, +y); | |
character.damage(); | |
console.log(character.toString()); | |
var player = new Player(+x, +y, name); | |
player.damage(); | |
player.move(7, 8); | |
console.log(player.toString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log({ | |
[+process.argv[2] % 2 === 0 ? "even" : "odd"]: +process.argv[2], | |
[+process.argv[2] + +process.argv[3]]: +process.argv[2] + +process.argv[3], | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var json = { | |
"name": { | |
"first": "Yosuke", | |
"family": process.argv[2] | |
}, | |
"birth": { | |
"year": 1982, | |
"month": 12, | |
"day": process.argv[3] | |
} | |
}; | |
var {name: {family: familyName}, birth: {day: birthDay}} = json; | |
console.log(familyName); | |
console.log(birthDay); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const max = process.argv[2]; | |
let FizzBuzz = function* (){ | |
let num = 1; | |
while (num <= max) { | |
let value = num; | |
num++; | |
if (value % 15 === 0) { | |
value = 'FizzBuzz'; | |
} else if (value % 3 === 0) { | |
value = 'Fizz'; | |
} else if (value % 5 === 0) { | |
value = 'Buzz'; | |
} | |
yield value; | |
} | |
}(); | |
for (var n of FizzBuzz) { | |
console.log(n); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const max = +process.argv[2]; | |
let FizzBuzz = { | |
[Symbol.iterator]() { | |
let num = 1; | |
return { | |
next() { | |
if (num > max) { | |
return { done: true }; | |
} | |
let value = num; | |
if (value % 15 === 0) { | |
value = 'FizzBuzz'; | |
} else if (value % 3 === 0) { | |
value = 'Fizz'; | |
} else if (value % 5 === 0) { | |
value = 'Buzz'; | |
} | |
num++; | |
return { done: false, value: value }; | |
} | |
} | |
} | |
} | |
for (var n of FizzBuzz) { | |
console.log(n); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arg1 = process.argv[2]; | |
var arg2 = process.argv[3]; | |
import Math from './solution-math'; | |
console.log(Math.PI); | |
console.log(Math.sqrt(+arg1)); | |
console.log(Math.square(+arg2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const PI = 3.141592; | |
var _sqrt = function(s, x, last){ | |
return x != last ? _sqrt(s, (x + s / x) / 2.0, x) : x; | |
}; | |
function sqrt(s){ | |
return _sqrt(s, s/2.0, 0.0); | |
}; | |
function square(x) { | |
return x * x; | |
}; | |
export default { | |
PI: PI, | |
square: square, | |
sqrt: sqrt | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arg1 = process.argv[2]; | |
var arg2 = process.argv[3]; | |
import {PI, sqrt, square} from './modules_with_name_math'; | |
console.log(PI); | |
console.log(sqrt(+arg1)); | |
console.log(square(+arg2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const PI = 3.141592; | |
var _sqrt = function(s, x, last){ | |
return x != last ? _sqrt(s, (x + s / x) / 2.0, x) : x; | |
}; | |
export function sqrt(s){ | |
return _sqrt(s, s/2.0, 0.0); | |
}; | |
export function square(x) { | |
return x * x; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rawArgs = process.argv.slice(2); | |
var args = []; | |
rawArgs.forEach(val => { | |
let commaSep = val.split(','); | |
commaSep.forEach(val => { | |
if(val !== '') args.push(+val); | |
}); | |
}); | |
function avg(...args){ | |
return args.reduce((a, b)=>a+b)/args.length; | |
} | |
console.log(avg(...args)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nodebrew install-binary stable | |
nodebrew use stable | |
npm install -g npm | |
npm install -g tower-of-babel | |
npm install -g eslint eslint-config-airbnb eslint-plugin-react eslint-plugin-jsx-a11y | |
$ mkdir workshop && cd $_ | |
$ npm init | |
$ npm install eslint --save-dev | |
$ npm install -g eslint | |
$ eslint --init | |
# Use a popular style guide | |
# AirBnB | |
# JSON |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment