28
Lecture 3: Additional Materials for ES6 ES6 on Windows + More ES6 + More Exercises Kobkrit Viriyayudhakorn, Ph.D. CEO of iApp Technology Limited. [email protected] http://www.kobkrit.com

[React Native Tutorial] Lecture 3: More on ES6/ES2015

Embed Size (px)

Citation preview

Page 1: [React Native Tutorial] Lecture 3: More on ES6/ES2015

Lecture 3: Additional Materials for ES6

ES6 on Windows + More ES6 + More Exercises

Kobkrit Viriyayudhakorn, Ph.D. CEO of iApp Technology Limited.

[email protected] http://www.kobkrit.com

Page 2: [React Native Tutorial] Lecture 3: More on ES6/ES2015

All source code• https://github.com/kobkrit/learn-react-native

Page 3: [React Native Tutorial] Lecture 3: More on ES6/ES2015

How to try ES6 and Beyond with on Windows

(1) Open Command Line with “Run as Administrator”

Page 4: [React Native Tutorial] Lecture 3: More on ES6/ES2015

(2) Create Directory at C:\es6 and then run “npm init”

Page 5: [React Native Tutorial] Lecture 3: More on ES6/ES2015

(3) Press Enter Many Times Until All Questions are Answered

Page 6: [React Native Tutorial] Lecture 3: More on ES6/ES2015

(4) npm install --save-dev babel-cli babel-preset-stage-0

Page 7: [React Native Tutorial] Lecture 3: More on ES6/ES2015

(4) notepad link.cmd

Page 8: [React Native Tutorial] Lecture 3: More on ES6/ES2015

(5) Type “doskey babel-node=.\node_modules\.bin\babel-node $*” and hit file > save

Page 9: [React Native Tutorial] Lecture 3: More on ES6/ES2015

(6) Go back to command line, type “link.cmd”

Page 10: [React Native Tutorial] Lecture 3: More on ES6/ES2015

(7) echo {"presets":["stage-0"]} > .babelrc

Page 11: [React Native Tutorial] Lecture 3: More on ES6/ES2015

(8) notepad 1.js

Page 12: [React Native Tutorial] Lecture 3: More on ES6/ES2015

(9) Type down some ES6 code, e.g., console.log(‘Hello World!’); + Hit Save

Page 13: [React Native Tutorial] Lecture 3: More on ES6/ES2015

(10) babel-node 1.js

Page 14: [React Native Tutorial] Lecture 3: More on ES6/ES2015

Alias is not persistence!• If you closed the command line windows, enter c:

\es6 again, and always run link.cmd

• Open command line program

• cd c:\es6

• link.cmd

• babel-node somefile.js

Page 15: [React Native Tutorial] Lecture 3: More on ES6/ES2015

More on .

Page 16: [React Native Tutorial] Lecture 3: More on ES6/ES2015

Math

Page 17: [React Native Tutorial] Lecture 3: More on ES6/ES2015
Page 18: [React Native Tutorial] Lecture 3: More on ES6/ES2015

Set

Page 19: [React Native Tutorial] Lecture 3: More on ES6/ES2015

Exercise(1) Write down a function that sum every element in array. E.g. sumArray([12,3,4,1,2,3]) = 25

sumArray([12,3,4,1,2,3]); //=> 25 sumArray([1,2,3]); //=> 6

Page 20: [React Native Tutorial] Lecture 3: More on ES6/ES2015

function sumArray(arr){

}

Page 21: [React Native Tutorial] Lecture 3: More on ES6/ES2015

Exercise(2) Write function that count word size case-insensitively.

wordHistogram('Hello world hello earth') //=> {hello : 2, world : 1, earth : 1 }

wordHistogram('dog eat cat cat eat dog') //=> {dog : 2, eat : 2, cat : 2 }

wordHistogram('Na na na na na na na na na na na na na na na na na na na na na na na na Batman!’) //=> {Batman! : 1, na: 24}

(https://www.youtube.com/watch?v=EtoMN_xi-AM)

Page 22: [React Native Tutorial] Lecture 3: More on ES6/ES2015

function wordHistogram(str){

}

Page 23: [React Native Tutorial] Lecture 3: More on ES6/ES2015

Exercises(3) Write the function that can unions two arrays and sort it ascendingly.

unionsAndSort([5,3,2],[1,4,5]) // => [1,2,3,4,5,5]

unionsAndSort([1,2,3],[4]) // => [1,2,3,4]

Page 24: [React Native Tutorial] Lecture 3: More on ES6/ES2015

function unionsAndSort(a,b){

}

Page 25: [React Native Tutorial] Lecture 3: More on ES6/ES2015

Exercises(4) Write the function that select only words that start with letter ‘a’ or ‘A’ in a string.

onlyStartWithA(‘angulus is an angle in latin’); //=> ‘angulus an angle’

onlyStartWithA(‘apple is not an animal’); //=> ‘apple an animal’

Page 26: [React Native Tutorial] Lecture 3: More on ES6/ES2015

function onlyStartWithA(str){

}

Page 27: [React Native Tutorial] Lecture 3: More on ES6/ES2015

Exercises(5) Reverse Digits of an Integer

reverseDigit(123); //=> 321 reverseDigit(-456); //=> 654

Page 28: [React Native Tutorial] Lecture 3: More on ES6/ES2015

function reverseDigit(num){

}