Beta
Arithmetic function plotter
10 of 11ivosdc
Loading description...
Arrays
Strings
ASCII Art
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.
This comment has been hidden.
Function arguments are named and represented inconsistently in the description and the initial solution ( and possibly other places ).
I'd suggest calling them by the same name everywhere, and representing specifically the
f
argument ( the first one ) as a string, which ATM it is, and not as a function ( which ATM it is not ) in the description examples. I haven't checked the test headers, but the same goes for them. Should you decide to make the first argument a function, then of course represent it as a function everywhere.I like this kata!
I suspect you could have gotten a different idea from all my issues, suggestions and comments, but I quite like the premise; it's just a number of design and implementation details I feel are worth improving ( which is .. kind of a pat on the back with a wrecking ball :yum: ).
Tanks for feedback in advance. I will refactor the kata depending on your suggestions. Just need a few days to get a timeslot for this ;)
Found the time yet? I have a Haskell translation more or less ready to go, but I'm waiting to see what changes need to be incorporated into that.
Bump.
I don't mind waiting, but I can also just do the Haskell version as a separate kata.
Hello Johan, I'm out of codewars for the last view weeks (private needs) and will be the next few weeks (project change). Can I give you access to the kata to contribute in it? I will do so. As I can see in the settings contribution is free ;)
I'll have a look. I don't know TypeScript though, so I can't change what I cannot also change there.
Thanks, anyway!
Fine! I like that it is ongoing. You can disable/remove the ts-code and optimize the kata with your suggestions :) When I'll be back in summer I will reimplement the TS. Although thanks - and happy coding! ;)
This comment has been hidden.
This comment has been hidden.
It appears the
x
parameter is the middle of the output grid. That middle is of course defined by two coordinates, and it would seem itsy
coordinate is also defined byx
.Is this correct; is this the best way to define the middle of the grid ( I think not ); and if correct, shouldn't this be described more fully?
how is height of chart even calculated ??!
Use appropriate datatypes. The function argument could be a function, unstringified.
This would also facilitate translations into languages that do not have
eval
, like Haskell; I would like to translate this into Haskell, but I'd have to write a parser from string to function and put it inPreloaded
( that's what it is for ), because writing a parser is a bit outside the scope of this kata.This comment has been hidden.
No, there is no reason.
I don't see any benefit in converting the output to an 'endless' string. Would you suggest to store every value in a single cell i would agree, because i'm able to test single values more easily.
I think it makes no difference if your output is an array of strings like it's done by now or just a long string.
I agree with Voile here - the semantics would benefit from the result being a newline-separated string. I don't think it's essential - if you don't want to, just don't, and close the suggestion.
Having a 2D array wouldn't make it any easier to test single values, because you can index a string exactly the same way as you can an array.
I do feel it's just inconsistent to have one
.join
over the 2D array; either zero or all of 'em would be more consistent. But that's just My Inner Autist peeping out. ( MIA has been known to be technically and morally correct, of course. Also, a jerk. :yum: )I guess it's about rounding numbers. I just set the point, if the coordinate in the display and the coords of the point are equal. So not every point is rendered. I will display the values in the tests to check this better.
I will have a look at your code, it seems better than mine! Thx for replie. Its my first kata.
Seems not to be a rounding problem, there are some y- values completely missing (not wrong, but missing) at different x- values... You can't see my code until i'm able to submit it and i don't know the x positions of your gaps;-)
These are my evaluated results for f(x) = x * x * x; (x: 1) (scala: 0.2) (range: -1 / 3)
You print e.g. (0.8/0.6). In my calculation it's (0.8/0.5) which can't be displayed caused by the matrix-resolution 0.2. Not every point can be displayed until 0.2 is a divisor for x and y. I got the 5 displayed valaues around zero (your solution) by string-cutting the values after the first decimal. I use currently .toFixed(1), which rounds too. Afterwards the values for +-0.4 becomes 0.1 (instead 0) which aren't displayed. I'm interrested in how you 'pressed' the values in the display-matrix?
This comment has been hidden.
Wow. Well done! Of course it looks better ;). I will hint to this behaviour in the description. And added further tests.
Your solution might be for an ongoing next kata "catch the missing dots" ;)
Difficult to hit your f(x) points (or not to hit your missing points;-)), but i added a new line which "helps", so submitted;-)... Perhaps you should change your task a little bit;-)
This still happens in the actual tests, both fixed and random:
A
+
is missing!This comment has been hidden.
In a few hours my work will be finished. I will have a look and think about optimization. By know i'm thinking about using your solution from yesterday -> printing all possible points (plus) So this theme would be obsolete.
Thank you all for input and discussing this :)
Good idea, so i have a working solution too;-)...
This comment has been hidden.
Still happens:
The problem is in your code, so no amount of changing the specs will fix it ;-)
Specifically, since the scale is a multiple of
0.1
anyway, you can just make it a standard unit and get rid of all the floating point numbers. Then there will be no floating point error.(Also I'd like the task to be reverted to the last version, where the scale of configurable ;-))
Yes, me to ;) This decission was time driven... For me there are two possibilities. Which do you prefer? 1- Should i revert the kata, 2- or work on a next step "plot with scalable resolution"
Maybe just revert it, I don't think "making the resolution scalable" is much of a change to make a separate kata about ;-)
Though you should probably keep
plot
as a function not inside an object, for obvious reasons.Thx for feedback :) I will revert. So this will be un-published until i have a solution as good as smile67 has ;)
There are still issues ;-)
Input: x * x * x, -0.2, 0.2, 10 Your result: f(0)=1 (many like this)?
fixed.
Really? f(0)=2?
This comment has been hidden.
I got two errors without my "...toFixed(8)" in line 3 (see my submitted code), so rounding is still a problem of this kata. I ranked it as 6kyu, the main difficulty was to hit your special calculated f(x) values not to plot the function or to write the code;-). The issue isn't completely resolved now, better to change the description/code: "... round the f(x) values to 5 digits and plot the function..." something like that;-) By the way it's not a bad kata, i like it (see this one, it's old and there's no eval function: https://www.codewars.com/kata/graphics-04-complete-function-grapher-~15-lines-of-code ):-)..
This comment has been hidden.
...now readable;-)? Do you think my code is not readable...? Three short lines are always readable:-)!
Of course, 'less code is always better' is a clean-code attitude, too ;)
.
There are no need to wrap plot in a function class explicitly, especially for such trivial purpose Also it should be a prototype function since it's not referencing anything in
Calculator
scope Moreover, it's 9102 already, please useclass
syntaxAll implemented. Thx for review.
Issue is resolved.
It's still a function in a pointless class in no reasons. Why is it inside a class? This is JS, not Java.
Also now the initial code has the wrong syntax.
Are you sure you actually know the
class
syntax? ;-)I did look up the class notation after ZED.CWT recommended this as bad code. I even don't know what is meant with: "Moreover, it's 9102 already..."
Plz. give me a hint, how a javascript-geek would like read the code. Both codings are working.
Initial code is not working because you wrote
function plot
insideclass
syntax. That's why I said it has wrong syntax.Anyways, the point is if you're going to put functions in an instantiated object, doing it with class syntax is better practice. However! In this case you don't even need to instantiate a class since you're just calling a function anyway, there are no states or anything. Why not just make
plot
a function and call it from test code?Thx :)
done
Please use
Test.assertDeepEquals(actual, expected[, message])
to test objects resultsdone
Needs Random Tests.
Done ;)
Done
Nope. Inputs, and therefore outputs, are entirely predictable. You could at least randomise the order of the tests with
const ranges = Test.randomize([5, 10, 20])
, et cetera, or, slightly better, generating all combinations and randomising that. Or you could really randomly generate values forx
,step
andrange
( within a reasonable range of course ) and randomly pickf
from a list. See some other kata how it's done; most follow the same template ( and some use ridiculously intricate patterns. don't read those :P ).