These are chat archives for FreeCodeCamp/HelpJavaScript

13th
Apr 2018
Serenity
@qmikew1
Apr 13 2018 01:37
@anthonygallina1 :thumbsup: (4 hours later 'thumb(s" up' - but, hey)
anthonygallina1
@anthonygallina1
Apr 13 2018 04:50
@qmikew1 :thumbsup:
Brad
@bradtaniguchi
Apr 13 2018 05:25
@anthonygallina1 :+1: I think I'm early, but I think its ok
anthonygallina1
@anthonygallina1
Apr 13 2018 05:36
@qmikew1 @bradtaniguchi thank you
CamperBot
@camperbot
Apr 13 2018 05:36
anthonygallina1 sends brownie points to @qmikew1 and @bradtaniguchi :sparkles: :thumbsup: :sparkles:
:cookie: 456 | @bradtaniguchi |http://www.freecodecamp.org/bradtaniguchi
:star2: 3764 | @qmikew1 |http://www.freecodecamp.org/qmikew1
Leigh Hobson
@leighhobson89
Apr 13 2018 10:44

with this loop, as long as arr2 is shorter or equal to the length of updatedInventory then existing stuff is added to the quantity or new stuff appended at the bottom, however there is a bug that if arr2 has extra stuff, or if more than one thing needs to be amended or changed, then only the first one is amended (which may be happening in any case actually) and the code to push the new element is not executed. can anyone tell me why?

  for (i=0;i<arr2.length;i++) {
    for (var j=0;j<updatedInventory.length;j++) {
      if (arr2[i][1] == updatedInventory[j][1]) {
        updatedInventory[j][0] += arr2[i][0];
        //console.log(updatedInventory);
        flag = 1;
        break;
      }  
      if (j == arr2.length-1 && flag == 0) {
        element = [arr2[i][0],arr2[i][1]];
        updatedInventory.push(element);
        console.log(updatedInventory);
      }
    }
  }

note: [i][0] is a quantity and [i][1] is a description i.e. [17, "BOOTS"]

if arr2 is longer than updatedInventory the bug is caused, sorry my wording was bad
Blauelf
@Blauelf
Apr 13 2018 11:29

@leighhobson89 You never reset flag to 0.

I'd place a flag = 0; before your inner loop, and move the if (flag == 0) (removing the j == arr2.length-1 &&) part after the inner loop. Because, what would happen if your updatedInventory started empty? Your inner loop would not run, you would never push a first element. If you move that part out of the loop, it's run whenever the inner loop does not find a match, regardless of whether that one had even a single iteration.

Leigh Hobson
@leighhobson89
Apr 13 2018 11:56
ahh yes thanks @Blauelf
CamperBot
@camperbot
Apr 13 2018 11:56
leighhobson89 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4690 | @blauelf |http://www.freecodecamp.org/blauelf
1Mher1
@1Mher1
Apr 13 2018 12:45
please help me to create this jQuery calculator they don' worked . , % and +/- https://codepen.io/1Mher1/pen/GxaGXM
Marianissimus
@Marianissimus
Apr 13 2018 13:02
@1Mher1 first, add jQuery to this pen, as you have this error: Uncaught ReferenceError: $ is not defined
you can do this using the settings - top right corner of the pen; then go to the javascript tab and select jQuery
Marianissimus
@Marianissimus
Apr 13 2018 13:04
now, as you see, it sort of... works. I mean it does your logic. please stop the background change, it's extremely annoying...
however, you need to rethink some of the logic; also - the functionality: I think you need at least a "Cancel" or reset button
Marianissimus
@Marianissimus
Apr 13 2018 13:08
Shouldn't you be able to chain operations? I don't remember perfectly this challenge, but I think so
If you do, this means the logic of your operations will NOT work = meaning $("#result").html(op1/op2);
You also need to find a way to always display the input on the screen;
1Mher1
@1Mher1
Apr 13 2018 13:09
no try + - / * this function worked
Marianissimus
@Marianissimus
Apr 13 2018 13:09
It's a lot of work, man, it's not a simple fix, sorry...
the functions work for only 2 numbers; don't you need to chain operations: meaning 2*3+6-1 ? what do you do then?
1Mher1
@1Mher1
Apr 13 2018 13:11
I dont now in this way wht can I do than I asked already to respond me and help me
Marianissimus
@Marianissimus
Apr 13 2018 13:12
take it one step at the time
first, fix your layout; you have a button out of place
maybe even add all the buttons that you need, like cancel
then, find a way to display all the inputs until cancel or enter is pressed
then, find a way to return the operations
Muhammad Hasham
@MohammadHasham
Apr 13 2018 13:49
can someone explain me this example
var add = (function () {
    var counter = 0;
    return function () {return counter += 1;}
})();

add();
add();
add();

// the counter is now 3
why counter = 0 won't run
Marianissimus
@Marianissimus
Apr 13 2018 13:51
when it first runs, counter is set to zero, but it returns counter +1; so, first run means counter = 1;
Pieter Stokkink
@forkerino
Apr 13 2018 13:51
@MohammadHasham The function that is returned from the IIFE gets assigned to add
so when you call that, there is a closure over the counter var
counter = 0 will run only once
Muhammad Hasham
@MohammadHasham
Apr 13 2018 13:52
so won't counter always take up zero at first
why once?
do i need to study something to get this wrap my head? @forkerino
Pieter Stokkink
@forkerino
Apr 13 2018 13:54
@MohammadHasham Immediately Invoked Function Expression
and closures
in a way
Muhammad Hasham
@MohammadHasham
Apr 13 2018 13:56
okay @forkerino thank's i'll try to get into it
CamperBot
@camperbot
Apr 13 2018 13:56
mohammadhasham sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2986 | @forkerino |http://www.freecodecamp.org/forkerino
Muhammad Hasham
@MohammadHasham
Apr 13 2018 13:56
thanks
Pieter Stokkink
@forkerino
Apr 13 2018 13:57
yw
It's not a very complete explanation, I remember there was some discussion in one of the You Don't Know JS books about IIFEs
which was quite good
lemme try to find it quickly
Marianissimus
@Marianissimus
Apr 13 2018 13:59
another question is why is counter not reset to zero in the 2nd function run, for instance; is it a global variable?
Nate Mallison
@NJM8
Apr 13 2018 14:00
@MohammadHasham I believe, and @forkerino can probably correct me if I'm wrong, when add(); gets called, it does not return the whole function, only the closure, the (func)() wrapped around the function means it gets called immediately when you load the script, so immediately counter is set to 0, and the closure function return function() {return counter += 1} is stored in var add. now when you call add(), it runs the closure function which increments the counter. And because of the closure structure ie: returning a function from a function, the state of counter is "saved" in the scope of the closure function. so it hangs on to counter = 0, when called it adds 1.
Pieter Stokkink
@forkerino
Apr 13 2018 14:00
@Marianissimus nope. The function that is run is the one on line 3, not the one wrapping it ( line 1 - 4 )
@NJM8 :clap: good explanation
you like typing more than I do
:P
Nate Mallison
@NJM8
Apr 13 2018 14:02
the key for me to understand it is that var add does not store the whole function, it stores the return function or the closure as they call it
Pieter Stokkink
@forkerino
Apr 13 2018 14:02
Nate Mallison
@NJM8
Apr 13 2018 14:03
@forkerino thanks. I was just reading about this yesterday in the YDKJS up and going, so I'm writing it for my benefit/ understanding as well, haha.
CamperBot
@camperbot
Apr 13 2018 14:03
njm8 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2987 | @forkerino |http://www.freecodecamp.org/forkerino
Marianissimus
@Marianissimus
Apr 13 2018 14:03
thank you @NJM8 @forkerino
CamperBot
@camperbot
Apr 13 2018 14:03
marianissimus sends brownie points to @njm8 and @forkerino :sparkles: :thumbsup: :sparkles:
:cookie: 398 | @njm8 |http://www.freecodecamp.org/njm8
:star2: 2988 | @forkerino |http://www.freecodecamp.org/forkerino
Nate Mallison
@NJM8
Apr 13 2018 14:06
var addFunction = function () {
    var counter = 0;
    return function () {return counter += 1;}
};

var storeAndCallClosure = addFunction();

storeAndCallClosure():
storeAndCallClosure():
storeAndCallClosure():
this code does the same thing, the wrapping (func)() in the other example just does the first run and storage for you
actually I don't think you need the () around func
var add = function () {
    var counter = 0;
    return function () {return counter += 1;}
}();
would do the same thing, you only need the () around the function if you want to run the function right away and not store it
Pieter Stokkink
@forkerino
Apr 13 2018 14:08
Not needed, but makes it more readable
in my opinion
otherwise I think we are dealing with a regular function
Nate Mallison
@NJM8
Apr 13 2018 14:08
true
anything to make closures and IIFE's more readable is good
Danny Chan
@chandanny
Apr 13 2018 14:21
hello
Muhammad Hasham
@MohammadHasham
Apr 13 2018 14:28
@NJM8 thanks now i think i get that
CamperBot
@camperbot
Apr 13 2018 14:28
mohammadhasham sends brownie points to @njm8 :sparkles: :thumbsup: :sparkles:
:cookie: 399 | @njm8 |http://www.freecodecamp.org/njm8
Muhammad Hasham
@MohammadHasham
Apr 13 2018 14:29
does IIFE runs only once?
and after that it shall run the inner annonymus function
which will increment the counter @NJM8 \
am i right?
Nate Mallison
@NJM8
Apr 13 2018 14:33
I think that is the idea. It's a function you only want to run once so you just call it right away. But I'm sure there are places/ reasons to do it again
correct!
I think. haha
Muhammad Hasham
@MohammadHasham
Apr 13 2018 14:35
@NJM8 thanks, looks like i can never claim to be an expert in JS
CamperBot
@camperbot
Apr 13 2018 14:35
mohammadhasham sends brownie points to @njm8 :sparkles: :thumbsup: :sparkles:
api offline
Nate Mallison
@NJM8
Apr 13 2018 14:43
@MohammadHasham We will all get there, I don't think many people can claim to be an expert, there is lots to learn!
Muhammad Hasham
@MohammadHasham
Apr 13 2018 14:43
yeah probably there is more than we think :-)
Nate Mallison
@NJM8
Apr 13 2018 14:44
I think it's more important to be an expert learner.
Muhammad Hasham
@MohammadHasham
Apr 13 2018 14:44
yeah! you are right
Blauelf
@Blauelf
Apr 13 2018 14:48

The nature of the IIFE is that you don't keep a handle.

parrot = (a=>(()=>a))("Arr");

I would not consider this an IIFE in a strict sense, even if it is invoked almost immediately:

parrot = (memorize = (a=>(()=>a)))("Arr");

(there's no need for a closure if I use "Arr", but think of a variable containing a string, I wouldn't want to keep a reference to the variable, but to its value)

But is there a definition how immediately an IIFE needs to be invoked?

Nate Mallison
@NJM8
Apr 13 2018 15:02
I think the need is just immediate if you want it to be, if I understand your question. I think they always run right away as the program is run the first time
@JLuboff @cmccormack I thought I would dive into things a bit after our convo yesterday: https://www.natethedev.com/arrayFlattenComparisons/
comparing speed of my steamrollarray function to lodash's using a shallow nested array and a deeply nested array. My first function was not great, usually 1.5X - 2X the speed of lodash's, testing against an array of 3000 items, one shallow nested one level deep, the other nested 14 levels deep.
I did note at first that _.flatten was suspiciously fast against the deeply nested array, but that is because of course it isn't for deep arrays so it wasn't flattening it all the way.
so I added appropriate tests for each function
BTW the results are in the console
Nate Mallison
@NJM8
Apr 13 2018 15:07
After refactoring my function to not use the new array iterators and a few simple ideas to make it faster, my function is faster than _.flattenDeep maybe 50% of the time.
and faster than _.flatten 80% of the time, rough estimates after running 9-10 repeats of the tests.
Take a look at the code, I'm no performance testing expert so maybe I made some mistakes. It's also interesting that my function is the first one run and that first run is usually the slowest, I wonder if the browser is doing performance enhancements when it sees all that recursion to optimize future calls, I'm going to try to run lodash's function first to see how it behaves.
Jason Luboff
@JLuboff
Apr 13 2018 15:20
@NJM8 Is performance.now() from a library? Or what is performance?
Nate Mallison
@NJM8
Apr 13 2018 15:22
it's provided by the browser
Jason Luboff
@JLuboff
Apr 13 2018 15:23
oh... i had no idea :D
I should test it in chrome too
looks like firfox rounds to two ms
Jason Luboff
@JLuboff
Apr 13 2018 15:26
When doing performance testing I;ve used console.time() console.timeEnd()
Nate Mallison
@NJM8
Apr 13 2018 15:26
Yeah I learned about that in JS30
I thought about using it but didn't
timestamps in chrome much more accurate
Nate Mallison
@NJM8
Apr 13 2018 15:34
well running the lodash function first doesn't make them slower, I bet they are doing something cool to alert the browser to run that code more efficiently somehow, or maybe they aren't using recursion, I don't think browsers are great at recursion. either way interesting to compare, even if the first lodash call is 2-3 times faster than mine, mine never hangs the website because the CDN or network is slow. :smile: . But of course in a back end environment lodash's flattendeep is much better.
If I know I have a shallow array I would use mine though.
Pieter Stokkink
@forkerino
Apr 13 2018 15:41
@NJM8 I would write some code that creates random arrays of random depth with length of ~100000 and test again. It would also make a lot of sense to put the flatten sourcecode in the test code.
also, I think storing your array length in a variable is actually slower, at least in V8 based engines.
Nate Mallison
@NJM8
Apr 13 2018 15:44
@forkerino Would you normalize it a bit though? like make the random array, test 10 times with each function, then make another random array, test all again?
that way there is a direct comparison
Jason Luboff
@JLuboff
Apr 13 2018 15:44
@forkerino :wave:
Pieter Stokkink
@forkerino
Apr 13 2018 15:46
@NJM8 You test each array with both functions and then create enough test cases (1000?) to make sure it works for all cases. You don't really need to test the same case twice if you have loads of test cases.
@JLuboff yo!
Daniel Simeonov
@dbsimeonov
Apr 13 2018 15:47
Guys have you tried to create custom search input with autocomplete effect. Is it something worth trying as a small project or its quite complicated for a beginner?
Jason Luboff
@JLuboff
Apr 13 2018 15:47
@forkerino How's it going?
Diego Mayer
@Chrono79
Apr 13 2018 15:51
:wave:
Jason Luboff
@JLuboff
Apr 13 2018 15:54
@Chrono79 Hey whats up
Diego Mayer
@Chrono79
Apr 13 2018 16:03
Tired
But still kicking
Pieter Stokkink
@forkerino
Apr 13 2018 16:08
@JLuboff long story, but generally ok.
Jason Luboff
@JLuboff
Apr 13 2018 16:12
@forkerino That sounds a little worrying..
@Chrono79 As long as you're kicking, all is good then!
Pieter Stokkink
@forkerino
Apr 13 2018 16:24
@Chrono79 :wave:
Jason Luboff
@JLuboff
Apr 13 2018 16:27
@forkerino How's the job going?
Pieter Stokkink
@forkerino
Apr 13 2018 16:28
@JLuboff apart from having the flu for the past 4 days, it's been great. Finally doing some python/django coding now as well.
Jason Luboff
@JLuboff
Apr 13 2018 16:29
@forkerino Awesome! (Besides the flu...that sucks)
Pieter Stokkink
@forkerino
Apr 13 2018 16:31
yup
@JLuboff How's the little one?
Jason Luboff
@JLuboff
Apr 13 2018 16:32
@forkerino Doing good, thanks for asking! We're still battling eczema with him, but otherwise he is a happy, healthy baby. He is able to rollover and starting to try to figure out the whole crawling thing
CamperBot
@camperbot
Apr 13 2018 16:32
jluboff sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2989 | @forkerino |http://www.freecodecamp.org/forkerino
Pieter Stokkink
@forkerino
Apr 13 2018 16:32
@JLuboff that's awesome. Soon you'll have to baby-proof the house!
Jason Luboff
@JLuboff
Apr 13 2018 16:34
That we will, how about your bigger-than-mine little one? @forkerino
Pieter Stokkink
@forkerino
Apr 13 2018 16:39
@JLuboff She's amazing, thanks for asking. She's getting really good at drawing and talking in three languages (two rather fluently, plus broken English :) ).
CamperBot
@camperbot
Apr 13 2018 16:39
forkerino sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2400 | @jluboff |http://www.freecodecamp.org/jluboff
Diego Mayer
@Chrono79
Apr 13 2018 16:40
What are the other 2?
Jason Luboff
@JLuboff
Apr 13 2018 16:40
I'm guessing dutch
And.... hmm...
Diego Mayer
@Chrono79
Apr 13 2018 16:40
portuguese?
Jason Luboff
@JLuboff
Apr 13 2018 16:41
I'm guessing an eastern european language
Regardless.... speaking 2 fluently and even a third is rather impressive
Pieter Stokkink
@forkerino
Apr 13 2018 16:49
Polish
her mother's from there
Jason Luboff
@JLuboff
Apr 13 2018 17:05
@forkerino That's impressive. Good on you both for teaching her so many languages
Pieter Stokkink
@forkerino
Apr 13 2018 17:17
it basically involves just talking in our own respective languages to her and english to each other.
Nazar
@IsaakNazar
Apr 13 2018 17:19
hey everybody !
maybe I need extra function for the second range, or single one is enough?
<body>
    <div class="pomodoro_container">
      <h1>Pomodoro Timer</h1>
      <p>Break Length: <span class="how_long break_length">1</span></p>
      <input type="range" class="ranges break_range" name="break" min="1" max="30" step="1" value="1">

      <p>Session Length: <span class="how_long session_length">1</span></p>
      <input type="range" class="ranges session_range" name="session" min="1" max="60" step="1" value="1">

    </div>

    <script type="text/javascript" src="index.js">
    const how_long = document.querySelectorAll('.how_long');
    const ranges = document.querySelectorAll('.ranges');
    const break_length = document.querySelector('.break_length');
    const session_length = document.querySelector('.session_length');

    function handleRangeUpdate() {
      console.log(this.name, this.value);
      break_length.innerHTML = ranges[0].value
      session_length.innerHTML = ranges[1].value
    }

    ranges.forEach(range => range.addEventListener('change', handleRangeUpdate))
    </script>
  </body>
Benji Kay
@okaybenji
Apr 13 2018 17:36
hi @IsaakNazar, I know this isn't quite what you're asking, but I think you might need to add another script tag
<script type="text/javascript" src="index.js"></script> <script>
since in the first one you're declaring a source
Nazar
@IsaakNazar
Apr 13 2018 17:39
@okaybenji yeah, I know, I just did this to show my code, actually this JS code is on a separate JS file, thx
CamperBot
@camperbot
Apr 13 2018 17:39
isaaknazar sends brownie points to @okaybenji :sparkles: :thumbsup: :sparkles:
:cookie: 110 | @okaybenji |http://www.freecodecamp.org/okaybenji
Benji Kay
@okaybenji
Apr 13 2018 17:41
@IsaakNazar ohh i see, sorry XD
i didn't do the pomodoro timer so i don't really have context to help with that specifically
do you have your code on codepen or something? i might be able to help by looking at the app
Nazar
@IsaakNazar
Apr 13 2018 17:47
@okaybenji ok, I'll give you a shout when questions pops up during this challenge :+1:
@okaybenji do you have an experience on ReactJS?
Pieter Stokkink
@forkerino
Apr 13 2018 18:05
@IsaakNazar I'm not sure I understand your question. Code looks ok.
Tiago Correia
@tiagocorreiaalmeida
Apr 13 2018 18:34
hey its good to see you @forkerino
Benji Kay
@okaybenji
Apr 13 2018 18:35
@IsaakNazar no, sorry
Pieter Stokkink
@forkerino
Apr 13 2018 18:41
@tiagocorreiaalmeida :wave:
Tiago Correia
@tiagocorreiaalmeida
Apr 13 2018 18:47
everything going well?
Jason Luboff
@JLuboff
Apr 13 2018 19:03
I've just learned a lesson... never going to run npm update ever again
Nate Mallison
@NJM8
Apr 13 2018 19:05
break something?
Jason Luboff
@JLuboff
Apr 13 2018 19:05
Broke several things
Express and dotenv
Nate Mallison
@NJM8
Apr 13 2018 19:05
really? What version were you on before?
Jason Luboff
@JLuboff
Apr 13 2018 19:06
Not positive. Not too old of a version, I started this project 2? months ago I think. Maybe 3
I guess I could go look at my git history for my package.json but I'm lazy
Nate Mallison
@NJM8
Apr 13 2018 19:08
the last version of 3 was released back in 2015, end of July
re running my steamroll vs lodash test with randomly generated arrays.
Jason Luboff
@JLuboff
Apr 13 2018 19:10
It was a dependency that got messed up for that. And then dotenv acted like it wasn't there. I dunno. Just uninstall and reinstalled both
Nate Mallison
@NJM8
Apr 13 2018 19:10
lodash beating me on the shallow version by an average of 1ms over 100 tests, I'm crushing lodash on the deep nested array by 4X though, 50ms vs 200ms
just rewrite express and dotenv, obviously
just kidding
Pieter Stokkink
@forkerino
Apr 13 2018 19:17
@NJM8 in the previous run, in my browser, flattenDeep was faster than your algorithm.
Nate Mallison
@NJM8
Apr 13 2018 19:22
@forkerino Do you know how much difference the computer makes? Mine is very old and struggling quite a bit in the cpu department
I wouldn't be surprised if I've done this all wrong and my algorithm is terrible, haha
Pieter Stokkink
@forkerino
Apr 13 2018 19:23
I think it was about 2x faster
I just checked the lodash source code and they only use one for loop
they do use recursion
I think btw that you can safely assume that lodash is pretty optimized
a lot of brainpower went into making it
@tiagocorreiaalmeida everything is a big word, but things are heading in the right direction.
@NJM8 do you have your current code somewhere I can run it? My laptop is pretty fast.
newest version is up, may take awhile to run
or I can give you the github to run locally
@forkerino I have no doubt that I'm not going to come up with a faster flattening algorithm than lodash in a day, that's not why I'm doing this.
Pieter Stokkink
@forkerino
Apr 13 2018 19:27
ok, just checking. ;)
steamrollArray deep test average: 56.86100000035367msecs
test.js:178 lodash flattenDeep deep test average: 27.92799999981071msecs
test.js:200 steamrollArray shallow test average: 2.4779999997554114msecs
test.js:201 lodash flatten shallow test average: 2.3409999997966224msecs
Nate Mallison
@NJM8
Apr 13 2018 19:29
Got into a discussion here yesterday about using lots of modules versus rolling your own code. My point is that for simple things like flattening arrays or making text camelCase I think it can be more trouble than it's worth to use a module
Pieter Stokkink
@forkerino
Apr 13 2018 19:29
depends
Nate Mallison
@NJM8
Apr 13 2018 19:30
mostly because I got a notification from github a few days ago that one of my projects had a vulnerability from an old package, it was a sub-dependency to another module, and what was it used for? converting a given time string like '2 minutes' to milliseconds.
Pieter Stokkink
@forkerino
Apr 13 2018 19:30
In most production environments you use a bundler like webpack to put everything together again, and separate files are useful for readability. For smaller things, it probably doesn't matter much.
ah, that sucks
post an issue on the package's github if there isn't any already
Nate Mallison
@NJM8
Apr 13 2018 19:31
so now my product is vulnerable to a Denial of service attack because someone decided to include a module rather than writing the 30 lines themselves
so yes it depends, but for simple stuff i think it's better to run your own, of course a well vetted library like lodash is great too. but I think you still have to be careful
Pieter Stokkink
@forkerino
Apr 13 2018 19:32
If it is actively maintained by a group or company, I guess it is pretty safe (short to mid-term at least).
Nate Mallison
@NJM8
Apr 13 2018 19:33
no matter what you are putting your code in someone else's hands, need to make an educated decision, not just, 'oh it's lodash I'm sure it's great', and move on
so I'm testing array flattening functions. haha
Thanks for the results, I'm curious as to why lodash is 2X faster on your computer and 4X slower on mine?
Pieter Stokkink
@forkerino
Apr 13 2018 19:33
but anyway, once you build a complex app, you will need to maintain your own code too.
I've seen browser updates mess things up
Nate Mallison
@NJM8
Apr 13 2018 19:34
it's true
hopefully I can just flatten arrays for the rest of my life
Pieter Stokkink
@forkerino
Apr 13 2018 19:35
@NJM8 I have no idea why the difference would be there. I'd expect (based on the structure of the algorithm) your algo to be slower (nested for is slower than single for by definition)
haha
Nate Mallison
@NJM8
Apr 13 2018 19:35
haha, that would be terrible
Tiago Correia
@tiagocorreiaalmeida
Apr 13 2018 19:37
good to know, how challenging where the last coding months ? :D
Nate Mallison
@NJM8
Apr 13 2018 19:37
@forkerino What is your machine? mine is sooooo slow
still waiting to load the website
Screen Shot 2018-04-13 at 3.40.49 PM.png
Pieter Stokkink
@forkerino
Apr 13 2018 19:42
@NJM8 Got an HP Omen 15 inch. i7 quad core @2.8 GHz / 16gigs DDR4 / 512 Gb SSD running ubuntu
Jason Luboff
@JLuboff
Apr 13 2018 19:43
@NJM8 I’ll try it again when I get back to work. I have an 3.4 ghz i7 (last gen), SSD, 16gb Ram yadda yadda
Pieter Stokkink
@forkerino
Apr 13 2018 19:43
@tiagocorreiaalmeida picked up some django and delved further into end to end tests
both are fun
But itching to learn more
also did some devops stuff so I can deploy our app in case other's are unavailable
Jason Luboff
@JLuboff
Apr 13 2018 19:45
@forkerino I may have to share a private repo with you later to see if you can help me with setting up some tests (if you have time/want to of course)
Nate Mallison
@NJM8
Apr 13 2018 19:45
Oh. I'm on a 2010 mbp. Core duo whizzing along. Lol
Tiago Correia
@tiagocorreiaalmeida
Apr 13 2018 19:46
nice @forkerino im also "starting" python, do you use mostly relational databases or the opposite?
starting to do some mysql with node @JLuboff but I feel it will be a pain compared to how simple it was with mongo :D
Pieter Stokkink
@forkerino
Apr 13 2018 19:48
@tiagocorreiaalmeida at work we use SQL type databases
@NJM8 One problem I see in the test.js is that you test different arrays for your algo and lodash. Ideally, you should test the same array for both (but only once).
that'll cut running time in half :)
Jason Luboff
@JLuboff
Apr 13 2018 19:50
@tiagocorreiaalmeida SQL is a pain with node, I’m getting used to it but it’s not as clean and concise as with mongo
Pieter Stokkink
@forkerino
Apr 13 2018 19:50
@tiagocorreiaalmeida SQL is a breeze with Django
Tiago Correia
@tiagocorreiaalmeida
Apr 13 2018 19:52
guess I have to start walking faster to get there @forkerino :D
Jason Luboff
@JLuboff
Apr 13 2018 19:53
@tiagocorreiaalmeida what module are you using? I’m using mssql, but I know there is sequelize which is ORM style like mongoose
Tiago Correia
@tiagocorreiaalmeida
Apr 13 2018 19:54
im using the mysql one since I had xamp allready installed
Jason Luboff
@JLuboff
Apr 13 2018 19:57
I just need to learn more about more intermediate to advance querying methods. I’m positive my queries are optimized
forkerino @forkerino is going to watch Dirk Gently
Pieter Stokkink
@forkerino
Apr 13 2018 20:03
:wave:
Ion Varsescu
@Nei-V
Apr 13 2018 21:52
 for (let v of permutation) {
            console.log(v);
            let testedLetter = v;
            re = new RegExp(`${testedLetter}{2}`, 'g');
            console.log(re);
            console.log(re.test(permutation));
            testing = re.test(permutation);
            console.log("testing",testing);
            if (testing == true) {
                console.log("test");
                //flag = true;
            };
        };
CamperBot
@camperbot
Apr 13 2018 21:52
:bulb: to format code use backticks! ``` more info
Ion Varsescu
@Nei-V
Apr 13 2018 21:56
Hello, does anyone knows why in the above example the console.log returns different result than testing variable?
to me they look the same
Stephen James
@sjames1958gm
Apr 13 2018 21:59
@Nei-V Which two console.logs?
Ion Varsescu
@Nei-V
Apr 13 2018 22:00
@sjames1958gm hi, the console.log(re.test(permutation)) and testing=re.test(permutation) - I expected them to be the same
Stephen James
@sjames1958gm
Apr 13 2018 22:01
Do you get true then false?
Ion Varsescu
@Nei-V
Apr 13 2018 22:02
in the first console.log - I get true, the second one ("testing") is false
Stephen James
@sjames1958gm
Apr 13 2018 22:03
If I recall correctly regexp hold state when you use the 'g' flag so it remembers and looks for the next value in the string
from MDN
If the regex has the global flag set, test() will advance the lastIndex of the regex. 
A subsequent use of test() will start the search at the substring of str specified by 
lastIndex (exec() will also advance the lastIndex property)
if you use 'g' flag and the same string
Ion Varsescu
@Nei-V
Apr 13 2018 22:05
aaaa ... it seems you recall correctly :) so I shoud just remove the first console.log ...I'll try it now
thanks @sjames1958gm
CamperBot
@camperbot
Apr 13 2018 22:05
nei-v sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 9197 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm