Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
abstracted or not, your solution _did_ introduce a bunch of new variables.
so you _very clearly_ fail at achieving the desired result with the very simple constraint.
granted, it's a very bad coding question for any kind of exam, because - either you do know the trick, or you don't. but that doesn't change that the answer failed. -
iceb11751ywhat that swap function does is basically a discarded third variable.
So I don't think your solution demonstrates what the question is trying to test -
@tosensei @iceb
That's not what I was told then. The professor told me below was what they were looking for as a solution.
X= 25 (First number), Y= 23 (second number)
Swapping Logic:
X = X + Y = 25 +23 = 48
Y = X - Y = 48 - 23 = 25
X = X -Y = 48 - 25 = 23
and the numbers are swapped as X =23 and Y =25.
Nothing about classes functions and all.
They looked for the above solution and didn't see it. So a 0. -
What kind of gamification (probably an insult to gamification) of education even asks a question like that? The tricks I have seen for this are not a good solution to any real world problems. We are not shaving off bits on systems anymore (even in embedded). This reinforces my decision to keep learning on my own rather than pay money for fucktards to try and "teach" me something.
-
New variables you introduced:
- Solution (typeof == "function")
- object (instanceof Solution)
Also, you didn't swap variables, you swapped fields on a specific object, so if the implied input and output are in local mutable variables you also created an `input` and a `solution`, both typeof == "object". -
Abstractions have an associated cost in JavaScript. It's important to recognize the ones that actually encapsulate something useful and eliminate the rest. This solution uses a lot of heap allocations when the problem doesn't need any.
-
But I also agree that this is a dumb exam question. Not like it matters, the purpose of a bachelor's degree is to certify conformance; by trying to be clever rather than simply sufficient you already failed the test.
-
@Sid2006 no. they looked for _any_ solution that doesn't introduce new variables, and didn't see _that_. it's that simple. your solution uses several new variables, so it fails. period.
it's kinda amusing how you can't see this simple and very obvious fact. -
@tosensei @AlgoRythm
You absolute troglodyte idiots. Right off the bat I established that my solution wasn't the correct solution. It was more of a creative choice. Read my rant again if u wish to.
And I literally told you what answer my professor was expecting to see and yet here you are saying all this bullshit.
People like you are exactly why StackOverflow is labelled toxic. -
@Sid2006 sorry, but people like you are why we have bad code, and why stackoverflow NEEDS strict rules.
and: your rant contains the phrase "In the context of this question, this is absolutely acceptable as a solution" - which is basically the polar opposite of "i established that my solution wasn't the correct solution" and doesn't at all correspond with the requirements. don't gaslight yourself.
it's wrong in every aspect, it's not creative or "ingenious" - just badly overengineered, it totally deserves getting 0 point, and you feeling pissed about that should only be you being pissed at yourself.
good for you that you know about abstraction, but you're missing something: when and when _not_ to use it. like a carpenters apprentice using a hammer to saw a log.
plus: SO is only labelled "toxic" by people who are just too dumb to understand what SO _is_. and knowing what _precisely_ stuff is is a core competency for developers - and those lacking it just.. suck at it. -
Hazarth95101yYeah, I'm sorry, but the others are right. You were asked to not introduce any new variables, and you introduced like 5
a passing solution has to ever declare and define only two variables, and no more at all. just having more "let" statements than 2 already disqualifies your solution, sorry, but it's like that :/
TL;DR - I came up with an ingenious version of a solution to a problem and still got 0 marks.
In my bachelor's degree we learned about abstraction, as usual for CS degree students.
In a later exam, a coding question asked us to swap two variables values without using a third variable and print the before and after on the screen.
You can read the question above again, because wait for it....
So this is what I wrote basically (JS equivalent solution),
class Solution {
constructor(obj) {
this.var1 = obj.var1;
this.var2 = obj.var2;
}
swap() {
return {"var1": this.var2, "var2": this.var1};
}
}
let input = {"var1":5, "var2": 7}
let object = new Solution(input);
console.log('Before');
console.log(input);
let solution = object.swap();
console.log('After');
console.log(solution);
Now look, before your boomer asses jump in and say "aCkChUaLlY tHiS iS iNcORrEcT"
I did include all kinds of comments that this is abstracted. The swap function is hidden away and the object variable doesn't need to know what it's doing.
In the context of this question, this is absolutely acceptable as a solution since the end-goal is to print the results on the screen and the user wouldn't see the source code.
I still got 0 on that question and I still get pissed about it sometimes, when I remember it, like just now.
rant