Giter Club home page Giter Club logo

exercises's Introduction

Hi there 👋

I am a fish touch front end engineer.

  • 🔭 I’m currently working on @zoom
  • 👯 I’m looking to collaborate on something (逃
  • 💬 Ask me about Anything

exercises's People

Contributors

maczyt avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

exercises's Issues

memoize

const memoize = func => {
  const resultMap = new Map();
  return (...args) => {
    let result = resultMap.get(JSON.stringify(args));
    if (result) {
      return result; 
    }
    result = func(...args);
    resultMap.set(JSON.stringify(args), result);
    return result;
  }
}

binarySearch code

🖖

const binarySearch = (arr, key, start = 0, end = arr.length - 1) => {
  const index = Math.floor((start + end) / 2);
  const middle = arr[index];
  if (middle === key) {
    return index;
  }
  if (index === start || index === end) {
    return -1;
  }
  if (middle < key) {
    return binarySearch(arr, key, index + 1, end);
  } else {
    return binarySearch(arr, key, start, index - 1);
  }
}

parallel & race

const promiseify = func => (...args) => 
  new Promise((resolve, reject) => {
    func(...args, (err, result) => 
         err ? reject(err) : resolve(result)
        )
  })
const parallel = fns => cb => {
  Promise.all(fns.map(fn => promiseify(fn))).then(p => {
    Promise.all(p.map(f => f())).then(result => {
      cb(null, result);
    })
  })
}
const race = fns => cb => {
  Promise.all(fns.map(fn => promiseify(fn))).then(p => {
    Promise.race(p.map(f => f())).then(result => {
      cb(null, result);
    })
  })
}

flattenthunk

const flattenThunk = func => fn => {
  const next = (err, result) => typeof result === 'function' ? result(next) : fn(err, result)
  func(next)
};

map

const map = (arr, iterator, context) => {
  const mapRes = [];
  for (let i = 0, len = arr.length; i < len; i ++) {
    mapRes.push(iterator.call(context || this, arr[i], i, arr));
  }
  return mapRes;
}

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.