Skip to content

Instantly share code, notes, and snippets.

@Gyumeijie
Last active March 9, 2018 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gyumeijie/da6248f36ee4798021d3498fc5bc6d80 to your computer and use it in GitHub Desktop.
Save Gyumeijie/da6248f36ee4798021d3498fc5bc6d80 to your computer and use it in GitHub Desktop.
usage of some important javascript functions
1. Array.reduce
有初始值:
If an initialValue was provided in the call to reduce, then previousValue will be equal to initialValue
and currentValue will be equal to the first value in the array.
没有初始值:
If no initialValue was provided, then previousValue will be equal to the first value in the array
and currentValue will be equal to the second
一般数值的用法:
numbers.reduce((acc, item)=>acc+item, init_val) reducer函数(acc, item)=>acc+item返回的值类型也是数字型的
一般函数的用法:
funcs.reduce((a, b)=>(...args)=>a(b(...args)) reducer函数(a, b)=>(...args)=>a(b(...args)返回的值类型也是函数类型的
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment