Created
February 28, 2018 10:47
-
-
Save haingdc/97413996d60fb50d4577e89646e99db7 to your computer and use it in GitHub Desktop.
A Gentle Introduction to Functional JavaScript: Part 2
This file contains hidden or 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 add = function(a, b) { | |
| return a + b; | |
| } | |
| var numbers = [1, 3, 5, 7, 9]; | |
| var total = 0; | |
| for (i = 0; i < numbers.length; i = i + 1) { | |
| total = add(total, numbers[i]); | |
| } | |
| // tổng là 25 | |
| function joinWord(sentence, word) { | |
| return sentence + ' ' + word; | |
| } | |
| var words = ['sparkle', 'fairies', 'are', 'amazing']; | |
| var sentence = ''; | |
| for (i = 0; i < words.length; i++) { | |
| sentence = joinWord(sentence, words[i]); | |
| } | |
| // 'sparkle fairies are amazing' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment