6 kyu
Deep and universal search by object
Loading description...
Trees
Algorithms
Data Structures
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.
not specified that 'obj' don't have any circular references, or maybe i misread)
Yup!) Thx, updated it
Fixed tests have
undefined
, random tests do not.Updated!) Thx :D
I solved the Kata. Were there any
NaN
s?no
NaN
is invalid JSON value.Array path being recorded as
.2
is not standard JSON path notation: it should be[2]
instead of.2
.Thx you for your feedback! I agree with you, I will fix it now.
fixed!
Hi again,
Raising the problem below as issue (you can ignore the message below): here are the hidden specs:
the correct expected solution assumes an object/array can never be a "match". That's why my code, when receiving
Boolean
as predicate, was extracting more values than yours.So (all these should be present in the sample tests and the full test suite):
Boolean
as predicate2
while"2"
is present in the tree (this should also be cleared out by the description)Order of the items in the output do not matter
: it's implicit, considering the output type (so it's sort of a "non information")Cheers
Hello again!) Sorry, I forgot to unpublish the task before making edits. I didn't have time to correct the mistakes yesterday. I will do it today and then I will write to you!) Thanks again for the feedback.
No problem. Unpublishing occurs automatically when 2 issues are raised on a recent kata, actually.
About predicates. Will this annotation be suitable?
A predicate can only be applied to primitive data types! Imagine it as if reference data types: objects, arrays, are all parts of a tree, branches like objects, or bird nests like arrays.
And that also
We must be strict when it comes to the data we are searching - if it is null, then we are looking for null; if it is '2', then we are looking for '2' specifically as a string, and any values found with the number (like 2) type will be incorrect.
the strict part seems OK, but the first one about primitives seems a bit edgy. most likely because of the story you put around it. not sure if it's a problem or not...
hmm. give me one minute :)
Okay, I will rewrite the lore. If I leave it like this "A predicate can only be applied to primitive data types!", can I publish it? I seem to have fixed everything you mentioned.
By the way, would you like to write an adaptation of the task for Python? :D
I'd prefere to reverse the wording: "don't apply predicates to objects or arrays" or something equivalent;
In any case, you can republish, yeah (don't forget you have to resolve the issues before you actually can)
Python: maybe, but I doubt I'll have the time, sorry.
Alright, thank you for your help. I have learned well and will approach the next task with a more correct approach.
you have hidden specs in the tests. Good luck with that: x)
missing fixed tests with null as value
I think your random generator is somehow broken: the very first random test always gives me somthing like:
So I think you systematically generate a function, and that function seems to always return true on the root object (not entirely sure...)
btw, you didn't specify what the expectations are about nested objects in arrays, as far as I can see (but I just made a quick sweep in the description, maybe I missed it)
Testing the generator :)
Regarding nested objects in an array, I described it in the "Notes".
'seems it's coming from your use of
Boolean
and an underspecification. Or rather, me twisting the resolution of the problem: the difference in our solutions is that I apply the predicate to the root object as well as all the other values. On your side, you never work with the root object the same way as you do with its children. I guess it's just a matter of specifications => "predicates must not be applied to the root object".Just reviewed your solution. By the way, your solution is amazing :). Just wanted to write about that.
thx, but so far, it doens't solve the problem... x)
ok, so here is the problem with the random tests:
arguments
param) => there should be ar random number of themall the sample tests should be present as well in the full test suite
I think this is a duplicate, actually (only difference being that you provide several arguments to search for, but that's not different enough)
yup, fixed!)
Thank you very much for your feedback! I will correct the mistakes in your last message now and then write back to you. If you have time, please review my task again.
random tests seems to be broken (I'd bet on your function calling mine through recursion):
Hi! Thx for your help) Fixed!
Hi,
no sample tests with a predicate-> the last sample tests should be renamedpredicate
instead ofhelper
.Cheers
About the output order, you chose a rather unusual way to handle it. In any case, it must be properly specifified, but imo it would be better to make the output order independant of the implementation details. Several ways to do so:
{path: value}
(<<< I'd choose that one, I think)I'm sorry, I didn't quite understand you.(2 and 3 point)
JSON will have the exact same problem than the current way: they are both sensitive to order of the values.
assert.deepEqual
will make life easy for everyone.Sorry. Sleepiness is playing a bad joke on me. I messed up with "JSON.stringify".
I understand you. Thx, I'll fix it)
By the way, if you're interested, I plan to add to the task and ask to return the value as an object.
Example:
Output:
I don't think it's a good idea. It defeats the initial purpose of the kata.
The original context was meaningful, asking for "the location of the values", and giving the answer in a human friendly way. That wouldn't be the case anymore. (sidenote: the
empty
things sound rather messy, also)Agreed, thank you. I will think more about how to play out this idea. The task involves an interesting use of "reduce". But first, I will figure this one out.
Now regarding your comment, I fixed the mistake as you advised. Can you review it?
I still get the
getValue
error in the random tests .(you can click on "wiew solution" under one of my messages to grab my current code and try it on your side)
sorry, copied the wrong code!) Fixed!)
no random tests
Sorry I'm new to this, bug accepted. I will write now.
Hello again. Thank you once again for your feedback. I have added some random tests. If you have time, could you please review them?
fixed