Skip to content

Instantly share code, notes, and snippets.

@haingdc
Created February 28, 2018 10:47
Show Gist options
  • Select an option

  • Save haingdc/97413996d60fb50d4577e89646e99db7 to your computer and use it in GitHub Desktop.

Select an option

Save haingdc/97413996d60fb50d4577e89646e99db7 to your computer and use it in GitHub Desktop.
A Gentle Introduction to Functional JavaScript: Part 2
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