7 kyu

Sum The Array

1,188 of 1,191vasekhlav
Description
Loading description...
Arrays
Fundamentals
  • Please sign in or sign up to leave a comment.
  • hobovsky Avatar

    This kata is a subject to deduplication process here: https://github.com/codewars/content-issues/issues/73 Please join the discussion to share your opinions, and help us identify duplicate kata and retire them.

    • hobovsky Avatar

      It's not conclusive whether this kata is a duplicate of "sum an array" taks, so for now it stays and will probably take part in deduplication of "extend Array prototype" set of kata.

      Suggestion marked resolved by hobovsky 3 years ago
  • filkovsp Avatar

    the kata is either ranked wrongly, or its Unit Test has a mistake, it's missing function call. so i decided to call my function addSumMethod but, for the Unit Test in order to succeed this function must be called before testing.

    So, this is how Sample Test must look like:

    describe("Tests", () => {
      it("test", () => {
        var tests = [
          [[1,2,3,4], 10],
          [[2,4,6,8], 20],
          [[93, 31, 62, 103], 289],
          [[397, 403, 764, 142], 1706]
        ];
    
        addSumMethod(tests);
        
        tests.forEach(function (x) {
          Test.assertEquals(x[0].sum(), x[1]);
        });
      });
    });
    

    And, tbh, i think the author should have done it themselves. With this small hack in Unit Test now it passes the SampleTest, but Attempt still fails :(

    • B1ts Avatar

      Well it works, because you created your own rules, but the tests are correct. You're not required to implement a simple function, you have to implement a function that is callable on Array itself (just like .map() or .reduce())

    • filkovsp Avatar

      oh yes, indeed, thank you @B1ts :) i see, i had to extend the Array class :)

  • y@ro Avatar

    Nice one! I would rate it as 6kyu thnx

  • donaldsebleung Avatar

    Good Kata, keep it up :D I ranked it 6kyu for the OOP and altering prototypes involved.

  • Unnamed Avatar

    Math.random should be called before the test loop, not in the condition (=> on every iteration).