7 kyu
The reject() function
3,171 of 4,303user5363957
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.
I like this kata. Thanks
C Translation
very nice one thx
very useful kata. makes me learn something new. thank you
I suggest improving the instructions and adding more test cases
There is a problem writing instructions?
This comment has been hidden.
This comment has been hidden.
Sorry to say, this is the most unclear kata i have ever seen. Please add some clearer description, such as the reject function needs to reject the iterator function.
Fixed.
Thanks
@FArekkusu i think not yet... still needs more fixation...
The description is non-existent.
Fixed.
python translation
Added Haskell and Typescript translations, please take a look.
They're mutually exclusive because they both modify the description differently. Also, no random tests ( Haskell, at least. didn't look at Typescript ). The fact that the original doesn't have any does not mean translations don't need them either.
If you add random tests and supply a unified description, I'll approve them both.
I was hesitant to add random tests since the javascript original didn't, but oh well. Changes made.
The second parameter really should be called "predicate", as it represents a boolean function, whereas the term "iterator" describes some kind of cursor that allows its user to traverse a container. There is quite a difference between those two concepts, I would say.
I did that way in my python translation. Thanks
Fixed.
PHP Translation Kumited - please carefully review and approve :D
Javascript version of Kata could have done with a lot more test cases, both fixed and random.
Hi, I've added a CoffeeScript translation, if you want to approve it, instructions for the approval process are here.
I have finished JS in codecademy, but they never explained about reject functions ! What to do now ? I thought this is a platform to learn and if so , how?
Welcome in CodeWars!
If in codecademy they never explained about
reject
function it's because this function doesn't exist. Actually as most of time in CodeWars you'll have to implement a new function. In this kata the function wil bereject
.As shown in the example . . .
. . . this
reject
function take 2 arguments :array
([1, 2, 3, 4, 5, 6] in the example)function
( function(num){ return num % 2 == 0; } ). This function get a "num" argument and returnstrue
if this argument is even (if num is odd then num%2==1).The
reject
function returns a new array. If you compare the array passed as argument and the returned array you can see the returned array is the same as the passed one except the even items were removed (or should I say rejected ? )So it seems the
reject
function should be a function taking 2 arguments (an array and a function taking succesively as argument each item of the provided array and returning a boolean) and returning a copy of provided array without the items which the function-test.Another example could be :
Hope it helps.
@danhin Pick 'Kata' from the left side menu so you can filter the kata. Choose 8 kyu. That is beginners level.
The task for this Kata is unclear. I supposed it needed an array with even numbers filtered out.
That was a really interesting program. After a few minutes, it actually became very clear what it was asking.
This comment has been hidden.
The user is not active anymore.
This comment has been hidden.
It needs a test case to reject the people who are accidentally returning the value, rather than
true
/false
This one gave me way more trouble that it ought to have.
Hello, I'm don't have experience in testing, i'm getting this result from my test and i don't get it:
Test Failed: Expected: [1,3,5], instead got: [1,3,5]
Use Test.assertSimilar instead of Test.assertEquals.
Works! Is this because Expected has the same value as got but is not the same object?
yes, that's the reason.
I don't understand exactly what I am being asked to do here :/?
neither do I... What exactly can the input be? More than just numbers?
The input is an array of values of arbitrary type for the first argument, and a function for the second. The signature of the
reject
function looks like this:I'm unsure whether I should post this information. If the kata implies discovering all this information on one's own, I'll remove it.
Hi,
Try adding some more test cases, for example test an array that contains only even numbers: Test.assertSimilar(reject([2, 4, 6, 8, 10, 12], function(num){ return num % 2 == 0; }), []);
Or only odd numbers: Test.assertSimilar(reject([1, 3, 5, 7, 9, 11], function(num){ return num % 2 == 0; }), [1, 3, 5, 7, 9, 11]);
The result from those should show you where you're going wrong.
Hi guys,
The test will pass with Test Passed: Value == [1,3,5]. When i try to save i get this error message Test Failed: Expected: ["a","b","d"], instead got: ["a","b",3,"d"]
I have no clue why? Someone can help?
Similar.My error message is "Test Failed: Expected: ["a","b","d"], instead got: [3]"
Me too.