Upload
kobkrit-viriyayudhakorn
View
2.379
Download
0
Embed Size (px)
Citation preview
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
All source code• https://github.com/kobkrit/learn-react-native
How to try ES6 and Beyond with on Windows
(1) Open Command Line with “Run as Administrator”
(2) Create Directory at C:\es6 and then run “npm init”
(3) Press Enter Many Times Until All Questions are Answered
(4) npm install --save-dev babel-cli babel-preset-stage-0
(4) notepad link.cmd
(5) Type “doskey babel-node=.\node_modules\.bin\babel-node $*” and hit file > save
(6) Go back to command line, type “link.cmd”
(7) echo {"presets":["stage-0"]} > .babelrc
(8) notepad 1.js
(9) Type down some ES6 code, e.g., console.log(‘Hello World!’); + Hit Save
(10) babel-node 1.js
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
More on .
Math
Set
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
function sumArray(arr){
}
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)
function wordHistogram(str){
}
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]
function unionsAndSort(a,b){
}
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’
function onlyStartWithA(str){
}
Exercises(5) Reverse Digits of an Integer
reverseDigit(123); //=> 321 reverseDigit(-456); //=> 654
function reverseDigit(num){
}