Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    I'm curious on all these .repalce() answers does the .trim() have to loop over the string a second time? I wonder if there is a way to get it in one pass?

  • Custom User Avatar

    Would this break when minified because there is no semicolon? Is semicolon best practices?

  • Custom User Avatar

    I had thought about doing this because my first solution was timing out. It is cool that it works. Great job.

  • Custom User Avatar

    This is what I did too, I was very skeptical of myself as I continued to nest the returns but very satisfied when it worked.

  • Custom User Avatar

    Well, while sample tests are indeed not obligatory, lack of them is often considered a kata problem, isn't it?

  • Custom User Avatar

    Not an issue. 11,000+ people completed in javascript. Press attempt.

  • Custom User Avatar

    In JS, I'm getting the wrong tests. The tests should be expecting an array of anagram matches or an empty array but they look like this ...

    // Since Node 10, we're using Mocha.
    // You can use chai for assertions.
    const chai = require("chai");
    const assert = chai.assert;
    // Uncomment the following line to disable truncating failure messages for deep equals, do:
    // chai.config.truncateThreshold = 0;
    // Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
    // Uncomment the following to use the old assertions:
    // const Test = require("@codewars/test-compat");

    describe("Solution", function() {
    it("should test for something", function() {
    // Test.assertEquals(1 + 1, 2);
    // assert.strictEqual(1 + 1, 2);
    });
    });

    And no matter what I do the tests won't pass, I can't get console logs to display anything in the left panel either.

  • Custom User Avatar

    Sorry for the late reply. So the empty string before I put the line number tells java that this is String addition. In this case, I am not sure it is necessary beacause I am adding another String right after. Also, I made this a long time ago, so this is not good coding practice at all. String addition is generally bad practice because it takes up extra memory (Strings are immutable).

    Just to answer your question more clearly:

    (5) is an int

    ("" + 5) is a String

    For clarity, String.valueOf(5) is probably better.

  • Custom User Avatar

    Hi I'm new. Why have the empty string before the line number?