7 kyu
Squeaky Clean
1,474 of 1,475user1496713
Loading description...
Arrays
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.
We don't need another lame, trival, low quality kata that does the same thing... --> https://www.codewars.com/kata/search/my-languages?q=filter&order_by=sort_date%20desc
I might as well post another wall of filtering based katas that I have collected (not done yet) here later to give some form of insights @glovastefan
Needs update to current Node version.
updated to nodev18
Out of interest, how did you update the kata?
If you directly edited it in the kata editor, please know that forking is ( now ) the recommended method.
I did it in kata editor, but will do fork next time.
Change the "var" in the description to "let".
Intent was apparently to filter falsy values. It has apparently missed
false
,-0
andNaN
since creation.There is now also
0n
, so the kata is now ignoring fully half of existing falsy values. ( So are some, though not all, solutions. )It is unspecified what to do about sparse arrays, which might be considered a special case of arrays with falsy values ( but that's probably solidly out of scope anyway ).
Trivial map/filter/reduce is not a novel idea, and I think there's already at least one kata asking to imlement an exactly same thing.
I am marking the issue as resolved, becuase Codewars comunity obviously like the Kata. Over 1000 times solved in Beta, with 93% satisfactory.
The community is not always right. This may still be a duplicate ( though it would be nice to have a link ), which would be reason for unpublication, the kata still being in Beta.
Johan is right. I upvoted this kata a long time ago, but I can't recall the reason for doing so. Johan's comment from 2 years ago does make me wonder whether the specification is even complete.
why not List Filtering?
Because so what if the items to be filtered differ? I could just as easily create a new kata tomorrow that asks to only filter [odd numbers and any string with the letter 'z'] or whatever. And the next day one with [even numbers and any string with the letter 'a'], ad infinitum.
Before someone approves it: random tests are missing.
In case the current test cases are seen as enough, feel free to resolve this issue :)
Added 100 random tests.
cool!
This isn't an issue!
Please correct word grammar, like "exisit" and "srting".
Typos corrected
There was a typo on the instructions.
Typos corrected
nice cata, helps me to learn new javascript method
This isn't an issue!
The descriptions for two of the tests are incorrect. The point of the kata is to filter out falsey values from an array, yet one of the tests says should ignore non-zero numbers. But it should it only ignore numbers that are zero.
Although it makes sense, depending on how you approach it, message has been updated to be more clear.
In the test case window, if you are typing in the last line, horizontal scroll bar appears over text your are typing.
Not a kata issue.
For any suggestions regarding the website (not a specific kata), you can open an issue here
Initial test case execution timedout because servers were busy.
Not a kata issue.
For any suggestions regarding the website (not a specific kata), you can open an issue here
suggested initial tests cases
testArray('Testing Valid Values', 'should ignore non-zero numbers', squeakyClean([1,2,3,0,1.1]), [1,2,3,1.1]); testArray('Testing Valid Values', 'should ignore non-empty strings', squeakyClean(['hello', '14', '']), ['hello', '14']);
There are already test cases like this in the main test suit.
Typo in problem statement.
Please remember to provide details as not all kata authors are native-english speakers
Typos corrected
This comment has been hidden.
This comment has been hidden.
This is totally not necessary:
The rest of the description provides plenty of information to solve this Kata. That part I quoted just makes it more confusing and I think it should be removed.
Kata description is a little misleading: it gives an impression that the clean function should return an array of removed values, while it is expected to return the filtered array of "truthy" values.
It clearly states what to return.
Should false be cleaned or not? If not, you need a test case.
This statement feels vauge: "and sometimes undesireable values like empty strings, 0, null, or undefined are stored during the session"
When you say "values like" it implies that this may not be the full set of cleanups required. It would be better if you were to clearly state that "squeakyClean should return a new array with all empty strings, 0, null and undefined removed".
Good point @greghmerrill - I've updated the description as per your suggestion. Thanks!
Was unsure if you wanted the original array cleanup, in-place, or a new array created with only "valid" values. Good idea, though.
OverZealous has already mentioned just about everything I would.
Sorry about the wall of text here. I got carried away. Most of this is somewhat general suggestion, and you don't have to do it all on this kata. I do recommend at least the first section. :-)
Your description refers to
null
orundefined
values. However, your test code has the function filtering the empty string (''
), which is notnull
orundefined
. It's better to explicitly define all the cases which should be considered, rather than rely on the user to infer your interpretation. This also helps in writing better tests, as you have a list of explicity values to test against.You've also do not have edge cases for values, such as:
false
0
'0'
[]
Which all will evaluate to
false
when checked via!!value
. If you decide to add edge these cases, them you should also explicitly list these as well, and provide specific tests.When writing tests, the message should be useful, preferably describing what value is being tests. Otherwise it provides no value, and can be omitted.
For example:
This provides no feedback to the user. It's a simple case, so you could either replace
"Failed"
with something better, such as"Should remove the empty string and null"
, or remove it completely, sinceassertSimilar
will report the actual and expected values.Even better, you can use
describe()
andit()
to group tests with descriptions, so you provide a sort of story for the user:Doing this not only makes your tests clearer and provide better coverage, but building up the tests from simpler to more complex helps the user find bugs faster and easier, rather than tracking down typos and other errors mixed in with more complex tests. Specifically, notice how I've tested against specific values, rather than mixing in multiple values to filter. This way, if the code works on
undefined
but notnull
, I have a specific test to compare against.This might seem like a simple kata, but, if I were writing this method from scratch, I can think of a few of ways to fail that might pass simple tests, but miss edge cases:
Also, I recommend you wrap your example code in single backticks (e.g.,
`null`
) for inline code, and you can use three or more backticks (or indentation) to format code blocks:or indentation:
I personally prefer multiple backticks, even for single lines, as you can specify the language (note the
js
after the initial set of backticks).thanks OverZealous for the feedback. much appreciated. i need to get a lot more detailed with this and will revise as needed.
@OverZealous, I have revised my kata to reflect your suggestions. Many thanks. Let me know if you see any other issues.
Looks much better.
Thanks