-
-
Notifications
You must be signed in to change notification settings - Fork 21
Add grade-school exercise #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Here is another possible approach: Copy (func $initialize) from resistor-color.wat The next two functions are adapted from C example.h addStudent(name offset, name length, grade) getGrade(grade) |
The C version keeps the current roster as input to the function and returns the changed roster. This would mean we would be forced to define the internal data format for the users, which is something that I really dislike, because it reduces the chances to be creative. In this case, you could have an u32 value for each student: [u16 offset, u8 length, u8 grade], similar to what I did for the tournament exercise. Also, most other assembly dialects are being called from C while WASM is usually called from JS. So it makes a lot more sense to look at JS than looking at C for the output. |
My suggestion omits the Test cases would be something like:
Perhaps instead of |
But there is no way to get the full roster then, so one of the asks of the introductions would have to be removed, which I would argue against. |
The canonical roster is simply a list of names, sorted by (grade, name) |
Then we could use the same format as the grade function. However, I haven't seen a language actually using that output. It is also pretty ambiguous. I would probably prefer the solution where the numbers of the grades are within their own lines, since it's simple enough to distinguish those from the names. |
Then let's keep that format and take an string of line-break-terminated names for both. |
Again the output format is a conundrum. While
roster()
is best expressed as JSON string, we would usually use a string with a line-break after each name forgrade(number)
. I wouldn't want to mix and match, so I see two ways to go about this.JSON would be obviously the exact same output that is expected from JS. A formatted string would introduce the next grade as a line containing only a number and a line-break, followed by all names ended with line-breaks, e.g.
Please share your opinion about which way to go.
The text was updated successfully, but these errors were encountered: