Normies gtfo, only real programmers ITT. So I started learning JavaScript and trying to submit my first challenge to leetcode but I can't because some wired runtime error. The solution runs perfectly in node. Whoever find whats wrong gets a cookie. Pic releated. Here's the code:
You're supposed to return an array, not a string. Use code tags.
Robert Robinson
> real programmers plz >JavaScript
Learn to use code tags. I find it to be bad form to put a template literal in a return. Clean up your syntax and problems might be more obvious. One of my first steps is always adding parenthesis to compound statements/expressions, or breaking up those into multiple lines.
Also, if you want to be a better programmer, consider finding ways to write code that more idiomatically describes the problem it's solving. I don't understand the point of this function. It finds two numbers from an array that add up to a given sun? Is there a more concise way to write this? Can you make it less confusing without losing performance? Could you have added a comment that makes it obvious what's happening and why you chose this design?
>only real programmers ITT. >trying to submit my first challenge to leetcode but I can't
Xavier Adams
>only real programmers >JavaScript Lmao what a fucking retarded nigger. Kill yourself faggot
Levi Rivera
>normies
Samuel Sanchez
You forgot to account for duplicates as well. Also you’re trying to return a tuple or something, just append the two results to an arraylist and return that.
Ayden Reyes
Spot on.
>I find it to be bad form to put a template literal in a return. Why? >It finds two numbers from an array that add up to a given sun? yes
>Is there a more concise way to write this? Can you make it less confusing without losing performance? >Could you have added a comment that makes it obvious what's happening and why you chose this design? Probably but I'm a total noob and just wanted to see if i'll be able to solve it with the first thing that comes to mind
Why do everyone hates JavaScript so much? I've only dedicated a few days of work. Should I switch to Python? My long term plan is getting a dev job without getting a degree
"You may assume that each input would have exactly one solution, and you may not use the same element twice." I did account for duplicates with i!==ii in the if statment
>only real programmers ITT >I started learning JavaScript Why don't you GTFO of your own thread OP?
Thomas King
> Why? It's just one of those things I usually see associated with bad code. I guess it's not necessarily a technical thing, but in my experience either the string should be created before the return, or the return should give the values and another function should be concerned with formatting the data into a string. It's usually a sign that a function is doing more than it should, unless the explicit purpose of the function was to return a string.
Cooper Parker
I meant duplicate values, say you had two sevens in there and a 14 was the target. I don’t think your code would push out 7, 7 as an answer. Could be wrong, I haven’t done Two Sum for months but I recall that being an issue for me.
Isaiah Diaz
With no degree and only knowing python or js, you'll be competing with pajeets and making similar money to if you just went and waited tables. If it fits into a longer path then go for it, but don't expect to make big bucks with that background and skillset. JavaScript and python are two languages that non-programmers learn all the time on the job. If you're picking these languages because they seem approachable, consider that any work that you can do with them that pulls in good money will be much more difficult than basic frontend web stuff or basic scripting. For example, some decent python jobs I've seen were projects that used python to script embedded controllers or interpret their data, which is not nearly as simple as doing some easy math or string manipulation. JavaScript is kind of a lang you'll probably end up wanting to know no matter what, but for really technical stuff, compiling other langs to webassembly will replace JavaScript, JavaScript will go back to simple interactivity, and possibly work as "glue" code.
Eli Cox
>Normies you need to go back
Eli James
I'd answer, but you're clearly a normie so you don't belong in this thread.