Ad
  • Default User Avatar

    Test functions for javascript:

    // TODO: Add your tests here
    // Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
    // [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
    // are still available for now.
    //
    // For new tests, using [Chai](https://chaijs.com/) is recommended.
    // You can use it by requiring:
    //     const assert = require("chai").assert;
    // If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.
    
    describe("Solution", () => {
      it("should test for something", () => {
        Test.assertDeepEquals(anagrams("abba", ["aabb", "abcd", "bbaa", "dada"]), [
          "aabb",
          "bbaa",
        ]);
      });
    
      it("should test for something", () => {
        Test.assertDeepEquals(
          anagrams("racer", ["crazer", "carer", "racar", "caers", "racer"]),
          ["carer", "racer"]
        );
      });
    
      it("should test for something", () => {
        Test.assertDeepEquals(anagrams("laser", ["lazing", "lazy", "lacer"]), []);
      });
    });
    
  • Custom User Avatar

    You're all mutating the array it seems.

  • Custom User Avatar

    Hello, can I please have help with this problem? I don't know how one is supposed to know if the anonymous function passed into the constructor will have any values or not.
    Additionally, I don't know how to make the dependencies in this.dependencies match up with the the array literal inside of the anonymous function.

    What I have done thus far is converted the this.dependencies object into an array, and then made a call to the anonymous method using the .apply method. (which is wrong).
    I'm at a loss for how you are supposed to solve this. And researching "dependency injection" just lead me down a rabbit hole of other things like "inversion of control",
    "unit-testing with Mocha", "promises", etc. Any hints would be greatly appreciated.

  • Custom User Avatar

    You're right, it is the same error for me

  • Custom User Avatar

    I figured out the same issue, in C#

  • Custom User Avatar

    Hello guys. can you tell me what the run time of your solution is? I think I have an O(2n) solution and my answer is also timing out.
    [UPDATE] I optimized my solution to an O(n) answer and its still not enough ;_; Is this broken?
    [UPDATE II] Okay, I optimized my O(n) solution so that it is no longer an exhaustive o(n) solution. I used a forEach() loop instead of a for() loop and broke as soon as I had my pair.

  • Custom User Avatar

    Hi, can I ask you something? Do you know what the runtime of your solution is? I'm using two reduce methods (1) to populate an object, (2) to find all instances where the sum of the current value is being matched with the difference of the current value and the sum. And accessing that sum is being matched by the object I have constructed earlier. I believe that my solution is O(2n), I just want to know what yours is because one would think that an acceptable solution would be O(n).

  • Custom User Avatar

    I too would like more directions on what this kata is even asking. So I'll just throw this comment in to draw more attention it it!

  • Custom User Avatar

    Oh yeah, I understand it now. I was just fresh 6th kyu who wasn't used to writing unit tests at the time lol. And dude, congrats on getting that 1st dan placement! Epic!

  • Custom User Avatar

    It should not happen.

  • Custom User Avatar

    I don't know if it is just me but I cannot console.log anything and I cannot see the values that I want to return. This testing stuff is the thing making this question hard but not the problem itself. This is for JavaScript.

  • Custom User Avatar

    I would like to inquire this as well but are the tests still failing for this particular kata? The tests seem to be reversing the order so it is saying that (Tests 0,0,1,0 ==> 2 Expected: 4, instead got: 2) which is not true at all. Basically, a lot of the tests are asking for the answer in the reverse way. This problem happens for me in JavaScript.