Beta
Functional JSON
Loading description...
Algorithms
Esoteric Languages
Interpreters
Functional Programming
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.
Random tests are of a fixed pattern, so they can be easily passed: see this
The actual argument name is
s
, notstr
.how we can get the input in javascript
I assume that the
~
operator only needs"in1"
since it's a unary operator, is that correct?Yes, exactly!
I have updated the description :)
I really don't hope that this kata gets 4 "Not Satisfied" votes :(
I really appreciate all your feedback, it really helped to make the description more clear :)
No worries, thank you for being so responsive! Now you have randomised tests there's actually a lot more effort required to complete it so hopefully you'll get some positive reactions soon. I'm afraid I'm putting it aside for a little bit however - I got stuck in some scoping issues on the factorial one that I'll need to think about for a while (I know I'm changing
n
too early, I'm just not sure when the right time is!). I will return though.You're welcome.
Good luck thinking :)
.
This comment has been hidden.
Cool, well done! I'm looking forward to see your solution :)
Me too - I refactored out the recursion and it still didn't work - just times out instead. It looks like it must be infinite looping for some reason but it's tough to debug and it passes all the other tests so it must be an awkward edge case. Not sure what might be causing that though so I'm refactoring more to make it easier to debug. I'm interspersing it with other things though so progress is a little slow. When I find what the edge case is I might suggest adding a fixed test to catch it. Debugging on a 'complex' algorithm is a real pain.
Yes, true. None of the tests should cause an infinite loop, but if you find a missing edge case, then I'll add that to the tests :) Can you explain which of the tests that's failing?
It's the list sort one.
Oh yeah, that's also the most complex one :) Do your code return the
arr
length when calling=arr.len
without a parameter? If not that would cause an infinite loop.=arr.len
should get the length ofarr
if no parameter is provided, since functions read variables from the global scope.This comment has been hidden.
Don't think I have that actually, will add that!
Added
Should use variables from global and local scope
, does that one pass for you?This comment has been hidden.
Here's a test for this scenario:
(JSON function)
My code is currently returning 3 as it's putting the value of
x
defined insidey
into the scope of the function call, when what seems to be wanted is for the scope to be whatever the scope was whenz
was defined, augmented with anything extra added when it's called with=z
.Would that be the correct interpretation of the requirements?
Actually that seems counter to the example in the instructions :(
Returning 3 from your example is correct, it doesn't matter when the function is defined but when it's called and what scope it's called in.
In your case you set x = 1, define function z in scope y, set x = 2, call z (add x + 1), when z is called x = 2. The same applies to the example from the instructions.
Does that make sense?
According to the tail function, then it must recurse, but only as long as offset is greater than 0, maybe you don't update the
offset
value properly?So that did make sense, but then in the 'tail' function
Looking at it again, I think I'm going wrong by setting the value of
arr
in thethen
before evaluating it. I guess since it's the last element you're not supposed to put its value into the scope until it's evaluated?When I set it too early, then arr is messed up for the next loop of
tail_
.I'll try going down that route tomorrow.
Exactly,
arr
should be updated with the evaluated value.You're almost there, well done!
Any progress here?
Not so much, I've ended up being busy with other things the last couple of days. I've got myself a good test case though:
This should give me "finite" if I solve the assignment issue, otherwise it'll infinite loop.
Yes, true! Btw, do you think it's enough challenge for a 2kyu?
Yeah, I'd say so. I've probably spent longer on this than I have on some of the 1kyus, but part of that might just be that I'm a little out of practice with JS.
Oh, wow thanks! I'm looking forward to see your solution ;)
Do you know what total code submissions is? I see there's 136 code submissions, but only 3 solutions (only 1 valid).
Are you stuck?
Yeah I'm not moving very fast with this, it feels like the solution I have so far will need to be mostly scrapped and redone :( so I'm taking a break from trying it, sorry.
BTW with the code submissions, I believe that's how many times someone has tried to hit 'submit' and run their code against the final tests.
No worries!
Thanks that makes sense :)
.
@Greatlemer, sadly there's not so much progress here from anyone.
@Greatlemer, what is your status on this one?
Hey @FastestCoderOnEarth, sorry I've not really been looking at any CodeWars stuff for a while so there's not been any progression from my side here :(
I think you have a typo here, the
then
andelse
shouldn't have an=
at the start should they?You're right, my bad!
For the respective string and array operations, does the associated variable have to be called
str
orarr
?Yes, should maybe make that clear in the description, thanks!
Also, is it an error if you try to overwrite a builtin?
Yes because
{"arr.length": {"string": "Test"}}
, shoulf throw an error bacause it's missing the propertya
.Updated description to make that more clear :)
Your interpreter must throw an error if:
str.at
is out of bounds.arr.at
is out of bounds.arr.len
.cond
,then
orelse
. (This implicitly states that built-ins can't be overriden).But if the key is "arr.length" doesn't that just make it a variable rather than a function call? Albeit one that can never be retrieved.
Ah, like that. No in that case an error should be thrown, because you try to call
arr.len
without all the required arguments.I have updated the description, and added test cases for that!
The example from the description (5 factorial) should be in the example tests so you have an example of the builtins in action.
True, added that to the example tests :)
Can I suggest you summarise somewhere in the description (preferably at the top as it's a long read) what will be required? Are we building something that parses a JSON document? Are we implementing all of the built-ins, a subset of them, or none of them? How are you expecting errors to be raised?
I have added a section to the description, thanks :)
Do you think that it describes the needed requirements?
Done!
Order of the keys in the object is not guaranteed.
Sorry, I don't understand what you mean.
Read this: https://stackoverflow.com/a/38218582/11589242
Yes, but if the object does only contain string keys, then this will not be a problem, or am I wrong?
If the interpreter is supposed to be handling JSON as an input then it should really be given the unparsed version. That way, key order is the responsibility of the coder and if the built in parser doesn't do what's wanted then they can write their own.
That sounds like a good idea, will do that, thanks :)
The JSON is now passed as a string, it's up to the coder to parse it and keep the order of the keys.
No random tests.
Yes, I also wrote that in my comment :)
I have added random tests!
BTW: You should maybe update your solution, it doesn't work anymore ;)
This is my first kata ever!
Feedback/suggestions is highly appreciated!
I hope you'll find this kata interesting!
Looks interesting to me. I hope it performs well :)
Thank you for the support!