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
-
iceb10912ywhat 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. -
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.
-
@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. -
Hazarth91342yYeah, 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