GithubHelp home page GithubHelp logo

30-seconds-of-js-code's People

Watchers

 avatar  avatar

30-seconds-of-js-code's Issues

其他功能方法

复制正则

const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags)

Math 相关

Average

const average = (...args) => args.reduce((acc, val) => acc + val, 0) / args.length

AverageBy

const averageBy = (...args, fn) =>
  args.map(typeof fn === 'function' ? fn : val => val[fn])
      .reduce((acc, val) => acc + val, 0) / args.length 

适配器

Ary

/**
 *
 * 用来控制传入参数个数
 *
 * @param    {Function}  fn     要改变的函数名
 * @param    {Number}    n      最多的可应用参数个数
 * @returns  {Function}         已格式化好的函数
 *
 */

const ary = (fn, n) => (...args) => fn(...args.slice(0, n))

Unary

/**
 *
 * Creates a function that accepts up to one argument, 
 * ignoring any additional arguments.
 *
 * @param    {Function}  fn     要改变的函数名
 * @param    {Number}    args   参数
 * @returns  {Function}         已格式化好的函数
 *
 */

const ary = (fn) => arg => fn(arg)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.