7 kyu
Number Of Occurrences
6,971 of 13,058madmed88
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 believe this to be a 6kyu.
where is the array
the keyword 'this' holds the array
it should've been specified, how could I have known
That's how prototypes work.
use "this", that would be array of object.
Does anyone know where the input array parameter is coming from? I've never seen a function written like this and this problem (JavaScript) is bad at explaining. There is no input value.
add your own
Added an input value by default, thx for noting that out
the keyword 'this' holds the array
JS translation adding random tests + fixing the issue by trashy_incel (link)
could one of you add the function paramater to the JS initial code ? it's missing and i cannot edit the kata :/
done
C translation (author gone)
The JavaScript version of this kata is teaching/suggesting bad style: with
Array.prototype.funcName = function () { ...}
, the prototype is extended enumerably, which means thatfuncName
will unexpectedly show up in array properties, which will bite the user sooner or later.Object.defineProperty(Array.prototype, 'funcName', { value : function funcName() { ... }});
should be used in the initial code instead.Changed by zenja.
Ideally, there'd be a test for non-enumerability, but too late to add that requirement now. :/
Also ideally, there'd have been a tested requirement to not mutate your inputs. Also too late. :/
Is it just me, or was it too easy for 7kyu.
Have been doing 3 kats in a row that were kinda straightforward, or maybe its time to move to 6kyu? How does one know?
Hey AbdallahSiyabi,
It's not possible to change the difficulty level of a kata after it has been published.
Cheers :)
Hey, I meant maybe it's time for me to start tackling 6kyu katas :D
In Python, test framework should be imported explicity on sample/random tests.
Fixed on this fork: https://www.codewars.com/kumite/6377e54550c7cb005593ade9?sel=6377e54550c7cb005593ade9
where are random tests for this ?
PHP translation
"Write a function that returns the number of occurrences of an element in an array." If the element is an "a" and there is an element "aba" in the array it should say in the description not to count letters there. It is unclear.
They're clearly two different elements.
Write a functionthat returns the number of occurrences of an element in an array. "functionthat" muse be devided into "function" and "that".
Corrected.
No random tests in Python.
JavaScript and CoffeeScript too.
Fixed on this fork: https://www.codewars.com/kumite/6377e54550c7cb005593ade9?sel=6377e54550c7cb005593ade9
The fork from heroicfun has been approved, so closing this issue
Prolog and CFML translations kumited. (author inactive)
Thx for helping add CFML translations! :)
There are no sample tests for Python and it's not clear what s is and what xs is (is the former a list or is it an int?)...
Also, when running sample tests, it just shows "Passed: 0 Failed: 1 Errors: 1" but no other message; how am I supposed to know what's wrong?
Fixed and fixed
Just to let others know, s is the integer while xs is the list
I recommend changing the names of the arguments for the function or at least including a description of what each one is in the description. I printed each to see which was the element to count and which was the actual array which is an unnecessary step
This comment has been hidden.
Maybe consider a re-write of the description or some test cases? I think for beginners knowing what 'this' is and how to use it, is unlikely and not being able to toss a test case or two in repl/fiddle/etc. makes it a bit tricky to get started.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
I've translated this kata to Swift, please review: https://www.codewars.com/kumite/582da07f5f867798b3000353
when a solution is submitted, this gets evaluated for various test cases and I see the results green passing all the test cases, then why this does not update the count of solved Kata. can you help me understanding the way this works. Any number of times I submit , I get only passed , once I leave the page , the code I entered disappaers.
Make sure you click the "Submit" button instead of "Run Tests", then click "Submit Final" to fully submit your solution. If you passed all the tests (0 failed) it should have been added to your account. If not, are you able to screenshot it and send me a link so I can see what's wrong? Also there should be a reply button under the comment thread which will reply to my comment.
It appears there is problem with the Internet Explorer browser. Even after correct SUBMIT, the Submit Final does not appear. Where as the same thing in chrome browser works fine. I have captured the screen shots, put to a word file. I do not know how to send the link etc.
Thanks for your support.
I am not able to understand, the way this site works. After I submit a solution, and see the result passing all , how do I get this recoreded to my credits. If I succeed in offering a solution and if it works without any errors, automatically the solution should be added to the credits. Am I not knowing where to click ???.
When you pass all the tests for any Kata, you will be directly to the solutions page where you can see other's solution. Depending on the difficulty of the Kata you just solved, you will automatically be given honor points (see here for information). If you want to see your previous Kata solutions, just go to your profile (click "View Profile" in top right hand corner), then click "Solutions". Is that what you're asking?
Time: 133ms Passed: 1 Failed: 0 Test Results: ✔ Test Passed STDERR: Traceback: in in number_of_occurrences IndexError: list index out of range
and wouldn't let me pass the exam. My code works perfectly on pycharm.
The output window shows: Time: 89ms Passed: 0 Failed: 0 Errors: 1
with no further feedback which is not enough.
This comment has been hidden.
This error means that you're trying to loop through something you can't loop through, like for i in 8: doSomething()
This doesn't makes sense, so Python gives you a TypeError. In this case, the simple problem is that the problem wants you to find how many
x
s are inxs
, not the other way around! Switch your line to: def number_of_occurrences(xs, x): and you should be good.OP solved it, closing
s is the output xs is the list of numbers
the test button doesn't work use submit instead since their are no test cases
(This is for python, not sure about the other languages)
This comment has been hidden.
Javascript version of Kata should ideally include random tests; keep that in mind when authoring future Kata :)
Please tell what s and xs are :). We can't just guess and make some basic test. Thank you.
xs = array s = element
According to the type signature, they're
a
and[a]
. Also, you have the Example tests.Closing.
It keeps telling me there is no code, even after clicking the reset button.
Help us help you. At the very least tell us what language you're having this issue with. Preferably include the relevant literal text of the message.
Closing.
Easy on js :)
This comment has been hidden.
Help us help you. Please mention which language this is, and format your code correctly indented.
Closing.
Ruby translation kumited.
(Description modified)
The description doesn't really match what's actually being asked (one argument instead of two) and it's impossible to figure out which argument is what without trial and error.
Agreed, method signature doesn't match the calls in the description. And variable names 's' and 'xs' are not descriptive. Bad test.
This comment has been hidden.
Should change description to:
sample = [0,1,2,2,3]
number_of_occurrences(0, sample) == 1
number_of_occurrences(4, sample) == 0
number_of_occurrences(2, sample) == 2
number_of_occurrences(3, sample) == 1
Should
makes it sound like a suggestion, not an issue. Also, why ?Closing.
In the python version, the instructions use a different signature for the function. Also, function parameter names suck.
Did you manage to figure this out? What is 's' and what is 'xs'? Former should be a list and the latter an 'int'?
Having some pre-set tests would be helpful.
Help us help you. Tell us which language you're having this issue with.
Closing.
You definately should specify, that element of array can be both string and number, because that's not obvious from Kata description. I've cheated a bit by watching on test cases before finaly passing this Kata, as my submit crashed on same testcase each time. Only from Kata test cases I've figured out, that element can be a string.
This comment has been hidden.
If n is in the array, then (c===n) will be true, and p (which is 0 because 0 was initial value) will be increased by 1. Remember 0 + true = 1. If there is no n in the array, then (c===n) is false, so p (which is 0) is added to false (+0) and returns 0.
This comment has been hidden.
In my browser, the #2 solution (using reduce) was much faster. Source: http://jsperf.com/code-wars-number-of-occurrences
This comment has been hidden.
I added one more new test case (to catch some hacky solutions that I noticed) and approved.
This comment has been hidden.
done
I did that in purpose. You should change the declaration. I edited the initial solution to avoid confusion.
This comment has been hidden.
This comment has been hidden.