Giter VIP home page Giter VIP logo

exercises's Introduction

Gitter

These are some basic (and advanced) coding challenges

Here's the basic workflow:

[~]         $ git clone https://github.com/kolodny/exercises
[~]         $ cd exercises
[exercises] $ npm install
[exercises] $ cd debounce
[debounce]  $ vi index.js
[debounce]  $ npm test

This uses a basic TDD approach so take a look at the test.js file in each directory to see what needs to be implemented, write an index.js as the solution file

Contributing

Pull requests welcome, please follow the basic workflow:

  1. Make a folder
  2. Copy a package.json from a sibling folder
  3. Make a test.js file
  4. Optionally provide a README.md

exercises's People

Contributors

2hu12 avatar ahw avatar asendia avatar danrevah avatar davidrunger2 avatar jedcn avatar kdamball avatar kolodny avatar marthaberner avatar nsluss avatar schmooie avatar skkeeper avatar staramir avatar susutou avatar trexnix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

exercises's Issues

The problem of the 4th test suite for `throttle`

Ideally, the 4th test suite for throttle, will execute every threshold ms, the throttled function will executed 6 times, as 1st time right away and every time when time counts to 10ms from 10 to 50.
But the test case is unstable, sometimes it passes, sometimes it doesn't. I test it on both my solution and yours. My method to verify it is to run this test case in a loop for multiple times, says, 10. This test case won't all pass.
I think the reason for this problem is the timeout 55ms of assert.equal is too strict.
Maybe you should consider reset it as 59, which I think it is reasonable.

And I run the same test with timeout 59, I got my solution all passes, also the other test case. But yours still won't all pass, I have not figure out what's your solution's problem yet.

Also I create a pull request about this.

link in "curry" prompt goes to incorrect article

This problem is fixed in #6 and #12, but curry/README.md links to an article on Curry, the language, rather than "Currying" as is described in the prompt. While Curry is a language that utilizes FP concepts, the technique of currying is much more widely applicable and does not derive it's name from this language.

Lookup count in binary-search test is not correct

First of all, thanks for this wonderful project.

When I started to do the binary-search challenge, I found there maybe some issues about the last test(the lookup count one). I have written 2 implementations, both implementations has passed all the tests except last one.

First one: the lookup count is 5000 in this implementation. I think maybe it is because the native implementation of array.slice has touched the get property. So I implemented the second one.

function search(arr, ele) {
  var len = arr.length;
  if (len === 0) {
    return -1;
  }

  var middleIdx = Math.floor(len / 2);
  if (arr[middleIdx] > ele) {
    return search(arr.slice(0, middleIdx), ele);
  } else if (arr[middleIdx] < ele) {
    var res = search(arr.slice(middleIdx + 1), ele);
    if (res === -1) {
      return -1;
    }
    return middleIdx + 1 + res;
  } else {
    return middleIdx;
  }
}

Second one: the lookup count is 11, not 13.

function search(arr, ele) {
  var len = arr.length;
  if (len === 0) {
    return -1;
  }

  function _search(startIdx, endIdx) {
    if (startIdx === endIdx && arr[startIdx] !== ele) {
      return -1;
    }
    var middleIdx = startIdx + Math.floor((endIdx - startIdx) / 2);
    if (arr[middleIdx] > ele) {
      return _search(startIdx, middleIdx);
    } else if (arr[middleIdx] < ele) {
      return _search(middleIdx + 1, endIdx);
    } else {
      return middleIdx;
    }
  }

  return _search(0, len);
}

So I guess maybe 13 is not correct. Could you help me to check this out? Thanks!

flipjs

Are there any instructions on how to run files through flipjs?

The only documentation on this is for a jquery library that does flipping animations.

Include use-case references

Not all developers may understand the context of how these exercises provide value and what their use would be in real world scenarios.

Perhaps including a description of what each of these exercises aims to help the developer learn, where that knowledge might be used, and the context of that use case could be helpful to include?

Incorrect throttle definition

In the test "it will execute every threshold ms", the result expected is [0, 11, 22, 33, 44, 55]
But If we strictly respect the definition of throttle (and the name of the test) :
throttle is used to make sure the function doesn't execute more than once _per_ x milliseconds
It should be [0, 10, 20, 30, 40, 50] right ?

Also, when I run the solution with

var interval = setInterval(throttled, 5);

I get [0,16,28,40,52] ; but it should be [0,10,20,..] ?
setTimeout should not take ms but the difference between the last call, in order to call the func as soon as possible.

How I see throttle according to the definition and the test "it will execute at least once more to make up for swallowed calls" :
With an interval of 6ms and 10ms for throttle (EDIT: Updated with 6ms)
Call 1 (0 ms) direct call ==> [0]
+6ms
Call 2 (6 ms) --> timed for 4s (not 10ms!) ==> [0]
+4ms @10ms Call 2 end ==> [0, 10]
+2ms
Call 3 (12 ms) --> timed for 8s (not 10ms!) ==> [0, 10]
+6ms
Call 4 (18 ms) --> clear Call 3 ; timed for 2s ==> [0, 10]
+2ms @20ms Call 4 end ==> [0, 10, 20]
+4ms
....
I know that doing this is not very relevant (at least with such low interval).
Maybe I'm just over-thinking the problem, but the definition (or the swallowed calls test) should be more explicit about this behavior.

EDIT 2 : Without this swallowed calls test weirdness, it would be even more simple. And we would get [0,12, 24, 36, 38] as 2 * 6ms > 10ms ; 1 call skipped each time. And it strictly respect the simple need of "limit to one call per x ms".

Thanks for this btw !

I'm doing it, show my code

now. I've done this

  1. async
  2. curry
  3. debounce
  4. flatten
  5. flatten-thunk
  6. invert-tree
  7. map
  8. memoize
  9. middleware
  10. once
  11. sort

this is my repo , thank you for your star or clone

I'm going to finish all

throttle-promises expectedHistory seems to be wrong

The expectedHistory is

0,1,2,3,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,3,2,1,0

but it should be

0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0

Comparing with this https://github.com/kolodny/exercises/blob/master/throttle-promises/test.js#L36 variable also makes the process stop responsing, don't know the reason

Create gh-page

To be easier to access it is needed a gh-page. Is it possible to do?

Example "sort sorts better than n^2" doesn't actually verify the algorithm's time complexity

Someone not familiar with time complexity might see that this spec is passing and assume that their algorithm is less than O(n^2), when in fact the algorithm might be O(n^2) or worse.

I would think it would be better to just call the spec "sort... can sort a large array" or something.

Or, on the other hand, maybe you actually could do something to verify the time complexity, along the lines of what is in the binary-search "uses a divide and conquer algorithm" example, maybe?

Add levels

Things like debounce should be level 1, throttle-promises should be something higher

Test suite for `throttle` appears to be incorrect

The throttle test suite has the following tests:

  it('gets called with context', function(done) {
    var ctx;
    var throttled = throttle(function() {
      ctx = this;
    }, 10);
    throttled.call(11);
    throttled.call(22);
    setTimeout(function() {
      assert.equal(ctx, 22);
      done();
    }, 15)
  });

  it('gets called with arguments', function(done) {
    var args;
    var throttled = throttle(function() {
      args = [].slice.call(arguments);
    }, 10);
    throttled(11, 22, 33);
    throttled(22, 33, 44);
    setTimeout(function() {
      assert.deepEqual(args, [22, 33, 44]);
      done();
    }, 15);
  });

In both cases, it appears that the test suite is expecting the throttled function to execute twice within the wait period. Is this test suite correct?

Shouldn't that last test's assertion be assert.deepEqual(args, [11, 22, 33]);?

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.