7 kyu
Flatten and sort an array
13,091 of 29,886lilsweetcaligula
Loading description...
Arrays
Sorting
Fundamentals
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.
C++ Translation.
Should be a 6 kyu problem in c
it says: arrays first differed at element [0]; expected:<1> but was:<3>. lol what is that?? the answer is correct why the machine answer with that?
What makes you think that your code works on your machine? It seems to miss an essential piece, it seems it would (almost) never return a valid answer. Does it work for you locally for the arrays from the example? Does it return the same answer as the example shows?
Codewars is the machine
Hello, for example i took the example: new int[][]{{3, 2, 1}, {7, 9, 8}, {6, 4, 5}}. using java the answer from my local is [3, 2, 1, 7, 9, 8, 6, 4, 5]. it seems correct, but pasting the source code and run on codewars it return error.
But it is not correct? The example shows that expected answer is not
[3, 2, 1, 7, 9, 8, 6, 4, 5]
, but something else?There is this example in description:
What does your solution return locally for the above input?
Yeah thanks, thats the problem. i forget to sort it. All good now.
Is it just me or was this one kind of easy for a 7 kyu?
I think it depends on the language you use, some languages have dedicated methods to flatten nested arrays, and some don't, and you'll have to figure the logic out.
In Dart, how can sort() be used if it returns void? At least that's what the API documentation says. https://api.dart.dev/stable/2.18.4/dart-core/List-class.html#instance-methods
Because they also use cascaded methods Also check this
Go translation
D translation
Rust translation
approved.
Haskell tests should be written in a way so the compiler still knows the types for the test cases without clearly inferable type so function can be written more general for any Ord a, instead of having to be type specific.
Hence, no.
This comment has been hidden.
Try now with Node version 12+, backup your code, click reset to update the sample tests, paste your code and try again.
This comment has been hidden.
This comment has been hidden.
I see, Thanks
Node 14 should be enabled (Refer to this and this for more info)
Done.
This comment has been hidden.
Not a kata issue, numbers can repeat.
sad.
COBOL translation, please review carefully.
Thank you. Approved.
🦊
F# translation - may need a PU as recent translations in other languages still outstanding?
Approved
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting#works-but-no
@CarolinFay You derive most benefit from your learning experience when you figure stuff out yourself. Sprinkling your code with
print()
statements may help you better understand what's going on. If you feel like you are stuck, take a break, try solving some 8kyu katas, and come back to this kata later with a fresh mind.Now for some tips - what are you using
set()
for in your code? I don't recall you needing sets for this kata.Thanks for the reply! I did test this one and used print() on the function with the array that doesn't seem to work - and I got the result that I should get, that's why I am so confused :/ I will try again tomorrow!
As for the set: I was trying to get rid of duplicates in the final list. Thought that was the easiest way but I'm probably mistaken then..?
@CarolinFay
Nah, you just keep duplicates in the result. It's not required to remove duplicates.
Why array.flat() is not a function in js ? JS has this method and it work in any EDI and DevTools.
See the node version required: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat
array.flat is a method in javascript and it works just fine in other platforms, so why the issue here?
check the aforementioned link; that method is not compliant will older versions of node
Because, as it is indicated on the page given by B1ts, it's available from Node JS version 11, and this kata uses version 8.
Thank you for asking this great question!
And thank y'all for the responses!
Whenever i run my code it passes the Test, but on the Attempt it throws:
Note: i added to the testcases
But it didnt work
Switch to py version 3.8
Thanks!
Now it's the default version
This comment has been hidden.
The latest Node version available for this kata does not support
Array.prototype.flat
.C translation
Thanks :)
Nice kata! however if a kata with multi dims instead of 2 dims exists then it could be really cool (idk if its there).
This comment has been hidden.
Python 3.8 should be enabled
fixed
Elixir starting solution is missing input variable in the function definition.
fixed
Expected and Actual outputs seems to be swapped in PHP
fixed
This comment has been hidden.
Python works fine. If you have a problem with you code, post a question, not an issue.
Also, you do know that Python is an interpreted language right? It isn't compiled.
Your code will fail everywhere when called more than once, don't use global vars. Also, the name of the function is wrong. Don't forget to mark your posts as having spoiler content next time, and also, use markdown formatting when posting code so it doesn't lose indentation.
Kotlin Translation kumited. Please review and approve if all is well with thee.
Rejected, see remarks in translation and translating example for reference
Swift 5 translation kumited. Please review and approve if accepable.
There's a clojure translation sitting...
Sorry, I have been quite inactive recently. I will gladly take a look.
JS, Python, probably other languages: missing an edge case test with an empty array/list.
fixed
CoffeeScript translation Dart translation Julia translation
This comment has been hidden.
Already answered.
This comment has been hidden.
Don't open more issues, read the posts already here, flat is not available in the Node versions this kata or Codewars currently support.
thx a lot :) now its clear now i got it, i am new on CodeWars:) but its strange...https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat flat is cwidely used..which version of node.js kata and Codewars have ??
In the trainer, next to Javascript, you can see/select different Node versions, this kata is only available in Node 6.11.0 and 8.1.3.
As MDN says, flat is available in Node 11.
This comment has been hidden.
Not a kata issue, please read the posts below.
which one as almost was hidden.....????
The one below? Steffan153's post is not hidden.
which one???
What? Is that anti-cheat?
No,
arr.flat
is available in Node 11And I said the same two posts below ;)
But I used babel, doesn't babel compile it? EDIT: Nevermind, babel doesn't for some reason. I guess babel doesn't compile every little thing.
I'm not sure what Babel does in Node 8 on CW... It was useful in previous versions, but now it doesn't support any new feature that I tried.
I mean, I tried it on the REPL and it did nothing.
well, it's time to update NODE
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
flat and flatMap are not supported for JS translation.
Not a kata issue, they're not available on Node below 11.
What is the expected behavior if the numbers in the input are not unique? Haskell QuickCheck keeps finding [[0, 0]], but neither [0] nor [0, 0] work.
If I remember correctly, and by looking at the solution code, the expected behavior for input
[[0, 0]]
is[0, 0]
. Now, I have to apologize for my ignorance here, but I am not very Haskell-savvy - if you happen to find a bug in the Haskell translation, please submit a patch.Not a kata issue, closing
basicTest failed array lengths differed, expected.length=11 actual.length=10 another tests OK What can be wrong?
Java translation, please review.
@hobovsky
Thank you. Approved.
Added PHP Translation :) https://www.codewars.com/kumite/5b718a7cc74d6540ce000054?sel=5b718a7cc74d6540ce000054 It's pending and need approvation
Haskell : https://www.codewars.com/kumite/5b68feaf20f95cf9d1000062?sel=5b68feaf20f95cf9d1000062
Really easy compared to other 7 kyu's! Thanks though!
Ruby and Crystal translations kumited, cheers :)
@GiacomoSorbi
Thank you. :) Approved.
Could do with random tests.
Random tests have been included. Thank you for your feedback!
Thank you!