Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
  • Jun 19 2020 20:09
    @krisb1220 banned @Gastony
  • May 14 2020 22:39
    @bjorno43 banned @minitechtips_twitter
  • May 14 2020 22:38
    @bjorno43 banned @real-action
  • Feb 01 2020 00:27
    @bjorno43 banned @Ndoua
  • Jan 07 2020 03:10
    @bjorno43 banned @doctor-sam
  • Aug 17 2019 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 2019 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 2019 17:13
    @mstellaluna banned @cmal
  • Jan 08 2019 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
Thomas Tylek
just as function foo(a) {return a;} doesn't need a to be declared
I clearly have much to learn.
Thomas Tylek
You'll get it man. I was just as confused as you at the start, if not more
Just keep practicing and asking questions
package addchain;

import java.util.*;

public class reeer {

    public static void main(String[] args) {

        int chainLength = Integer.parseInt(args[0]) + 1;
        int chainTarget = Integer.parseInt(args[1]);
        Random rng = new Random();
        List<Integer> chain = new ArrayList<>();

        while (true) {
            while (chain.size() != chainLength)
                chain.add(chain.get(rng.nextInt(chain.size())) + chain.get(chain.size() - 1));
            if (chain.get(chain.size() - 1) == chainTarget) {
i am getting this error
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at addchain.reeer.main(reeer.java:9)
can anyone help plase
Thomas Tylek
@TonyRednil Anyway, args.includes(1) evaluates to false. But that's the value you want to keep, so !args.includes(1) evaluates to true
@TonyRednil practice running through those steps and talking through each arr[0] and then arr[1] kinda like i started to show you
Ooh, @Devansh-Anhal , I don't really know Java at all but I'll try to help
@Devansh-Anhal , you do realize this is a front-end help chat room? (HTML, CSS, JS)
oh sorry :P
i am really sorry
Thomas Tylek
no need to be sorry! I just don't know how much I can help you buddy!
Mois├ęs Man
what this does ? rng.nextInt(chain.size()) @Devansh-Anhal
Santiago Fernandez
i always forget where the actual talking takes place here :/
Have a few Js doubts, im submitting some code for an interview, and some questions came up regarding style which i
d like to talk over if anyone's around :D
Style is great, since anyone can talk about style and no one is right XD
Santiago Fernandez
well, not style tbh
im just not sure about some things that i know work, but wonder if its the correct way to write it :/
like maybe im overextracting stuff into functions. i try not to compromise legibility and "ease of following wtf is going on"
but then again, DRY stabs me in the face and i HAVE to avoid repeating stuff :D
all in all im not satisfied that the implementation works, but i'd like the code to look nice... despite the fact they know i havent worked more than a few freelance projects (and you pretty much make up the rules as you go there)
I mean its really realtive. Do you know if you can find out if the company your submitting your code to has any style guides? (might be able to do some digging)
otherwise the general stuff should be ok. Idk if you code looks like a mess so idk past that
Santiago Fernandez
they dont, one of their front end leads is a good friend of mine and he agrees on my approach "i dont know everything, this is the best i can do"
mayhaps just need to vent it out a bit and then click the send button with what i've got :D
I mean i don't see how style could hurt you as long as its not total garbage haha
Santiago Fernandez
take the following
function a(){
i just feel that is dirty for some reason
but it does help me handle an event on the browser in multiple places, by using a() and keeping each eventhandler short
I usually don't nest functions, unless there's some sort of OOP going on
were talking about vanillajs right? Opens up alot of ideas on style
Santiago Fernandez
constraint is use no libraries, no frameworks, just vanilla
Yea, id still stick with the no nested function thing (besides an Iffe)
Santiago Fernandez
so just repeat the code?
i am wrapping all those methods (b,c,d) inside another method basically, that is my approach, to avoid repeating like a madman and spanning 150 more lines of code
what? whats wrong with:
function a() {
  addEventListener.on('click', b);
function b() {}
function c() {}
function d() {}
Unless your using the same functions, (b,c,d) on different elements or something I'm missing
Santiago Fernandez
yea i am
i have click handlers for left arrow, right arrow, and then a nav with different positions
Ah, I guess the naming of b,c,d isn't the best :P
Santiago Fernandez