8 kyu
Array plus array
43,666 of 88,041Dmitry Kudla
Loading description...
Fundamentals
Arrays
Debugging
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Lua translation!
Approved
I LOVE PYTHON
How does this equal 2100???
It should be 600
it doesn't and there's no such test and thus this isn't an issue
This is not a Kata issue. You have probably accidentally modified the sample tests. This is NOT part of the sample fixed tests, nor the submission fixed tests or the random tests. The actual test case is
assert.strictEqual(arrayPlusArray([100, 200, 300], [400, 500, 600]), 2100);
, which is indeed correct. If this is causing you to not be able to submit, copy your solution, click theRESET
button below the sample tests, and paste your code back. Any accidental tampering with the sample tests should be removed by then.Perfect
I don't really understand why this has the debugging tag. I was expecting code to already be written that was being debugged, not writing the code from scratch.
Not that it was difficult, just felt misleading and inconsistent with other kata's I've done with the same tag.
pretty easy :D
RISCV Translation
Approved
Yet another 8 kyu (the smiplest) task which is not that simple actually. But it is good practice, I liekd it.
This comment has been hidden.
Some languages have such tests. This constraint isn't mentioned in description, but the author probably chose equal arrays anyway. I don't think it would impact the rating at all.
Shouldn't all of them do that? I was wondering if there is a reason why they don't.
I think it is important thing to think about (that arrays may have different length) and therefore to test for. Arrays could be empty too but I guess the description vaguely hints that there will be integers (and only) inside.
Do you think it would make sense for me to extend the test cases? Assuming I am allowed to do so.
Description mentions that
Each array includes only integer numbers
. So, empty arrays should not be considered. Also, arrays of different length do not affect how such problems are solved, so I would say it is more on perspectives. Plus, unifiying each language in terms of test cases can be difficult because translations can be done by any user once they reach a specific honor threshold, though efforts on improvising these have been done more actively latelyThat makes sense. However, such tests would invalidate some (incorrect) user solutions. It doesn't matter if arrays are of size 4 or 5 but it does matter if one array is 5 and the other 4.
Dart translation
Approved
This comment has been hidden.
You should not share your solution openly. This is including risk for who does not solved the kata. Use the spoiler button please.
This comment has been hidden.
Please just
Submit
your solution instead of posting spoilers inDiscourse
.Best question to start working on arrays, (with java solved)
I solved the problem, but the check showed that there are errors, although everything shows correctly. I had to take the correct answer from other users. There was a residue...
Lol no way this is 8kyu lmaoooo! Never even learned the "..."
This comment has been hidden.
This comment has been hidden.
TypeScript translation
Approved
Tried different solutions, each time passing all the cases except for one, which I can't even see in the output section. Python
it eventually worked
Close the 'issue' then?
yep, sorry for not doing this
Coffeescript translation
Julia translation
R
(author inactive)
Thanks :)
This comment has been hidden.
An array of length 2 has indexes 0 and 1, so if you do
i<= arr1.length
, it will try to accessarr1[2]
and you'll get an out of bounds error.Thank you.. That is a really clear and simple explanation..
I feel that this is a poorly worded question. It is obvious what is to be done, but first read made me think that I was summing element-wise and returning an array.
Why is the exercise worded like a question from stackoverflow?
Most likely to make you laugh.
Clojure Translation ready for review.
the fun part is that kata "Beginner - Reduce but Grow" was right before this one !
so, in reduce(); what do accumulator and currentValue do?
You can read that, here
Thanks
This comment has been hidden.
That's because
Array.prototype.flat
is available since Node v.11 and CodeWars uses Node v.8 or v.10. To make it work on CW, you need to replaceflat
with something else.Rust translation
My code works BUT WHY DOES IT NOT ACCEPT IT AS AN ANSWER, plzzzz someone explain. Sorry for the rage lol, I just dont understand. I can literally send someone my code and it works but I dont get why it wont accept it.
Try harder.
This comment has been hidden.
Factor translation ready for review.
This comment has been hidden.
There are languages without operator overloading. There are languages where
+
is already used for concatenation. If you overload+
in a language where it's possible, it's not immediately clear what it does. Maybe it's OK when it's a whole library that consistently overloads arithmetic operators, but here it's just one function.Not applicable due to reasons stated above and high completion
CFML Translation!
This comment has been hidden.
Please, stop posting how to solve the katas. That's forbidden.
I love it when these kata take less than half a minute.
Typescript and Julia translations.
Prolog translation kumited.
Please, NASM Translation Please, C Translation
Approved
This comment has been hidden.
( Haskell, possibly others )
Dsperately needs tests with arrays of unequal length. Description does not specify this is impossible, and several solutions ( including the friggin' example solution ) presume this.
Also, needs random tests.
Fixed Haskell version.
Was it fixed for Python? One of the solutions would crash with an index bounds exception if the array lengths differened.
I think there is an error in the current Haskell code. I tried a number of the accepted solutions and they failed.
Did you choose the correct Haskell version?
Just tried to reproduce and everything seemed to work fine, so maybe it got fixed.
This comment has been hidden.
The solution you've mentioned has indeed passed the test as of now (6 years later), hence closing...
[C# translation] (http://www.codewars.com/kumite/5a6082d7e6be387388000015) added :)
Crystal and c++ translations; the latter using vectors, as sticking to arrays would have made it significantly harder than a 8kyu in c++ :+1:
"Testing for arr1: [3439, 6163, -7789, 811, 1104] arr2: [-6422, 5565, 5526, 6233, 4736]"
Expected: 35004, instead got: 19366
I pass the basic test, but literally failed all of the random test. That is one of the random test. Why is it expecting 35004 instead of 19366? 19366 should be the right answer right?
Don't mutate the input
Thanks, finally pass it. But why it can pass the basic test, but not the random test?
Post your code here and make sure you Mark it as spoiler.
The basic tests are compared against a fixed number, the random tests use a funcion on the same input arrays to get the result, so if you mutate the input the values returned by that function are wrong.
Python translation Kumited
Please review and approve.
done. Not camelCase for python? (function's name)
I used snake_case, not camelCase.
Camel case is not acceptable.
Is es6 is supported here?
absolutely
Is there really a difference, adding the values of one array or adding the values of two arrays? https://www.codewars.com/kata/sum-arrays (and there are others too) For me again a duplicate... By the way really boring these days the lot of weak katas, often with wrong or missing tests too, bad description a.s.o.
deleted (codewars error)
The last test of the example test is wrong. Fix it, please.
I've fixed it, thanks a lot