Skip to content

Instantly share code, notes, and snippets.

@juwencheng
Last active May 21, 2017 09:06
Show Gist options
  • Save juwencheng/d40ebd0a01741152e47e1535ae69404f to your computer and use it in GitHub Desktop.
Save juwencheng/d40ebd0a01741152e47e1535ae69404f to your computer and use it in GitHub Desktop.
// section 1
// let sum = function(...args) {
// return args.reduce((prev,curr)=>prev + curr)
// };
// console.log(sum(2,3,4,5))
// section 2
// let multiply = (mul, ...numbers) => {
// console.log(mul,numbers)
// return numbers.map((n) => {
// return mul*n
// });
// };
// let result = multiply(2,7,4,5)
// console.log(result)
var numbers = [4, 6, 3, 8];
// we can pass array to Math.max method,
// so we should change the method
// let max = Math.max(numbers) //error
// refer:http://devdocs.io/python~2.7/library/functions#apply
// equivalent Math.max(*args,**kwargs)
// let max = Math.max.apply(null, numbers)
// console.log(max)
// rewrite
var max = Math.max.apply(Math, numbers);
console.log(max);
// concanate
var newNumber = [3, 4, 34, 4].concat(numbers);
console.log(newNumber);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment