These are chat archives for FreeCodeCamp/HelpJavaScript

12th
Mar 2018
abraham anak agung
@padunk
Mar 12 2018 04:17
Hi all, is this code can be refactor again? simple manual sorting function.
var arrToSort = [4,9,7,1,3,6,5];

function sortIt(arr) {
    for (let i = 0; i < arr.length; ++i){
        for (let j = i + 1; j < arr.length; ++j){
            var temp;
            if (arr[i] > arr[j]){
                temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
    }

    return arr;
}
Sweet Coding :)
@SweetCodingInc
Mar 12 2018 04:23

@padunk It is a general observation that if you iterate over your arrays backwards, it works much faster.

You can declare your temp inside the if condition. like var temp = arr[i] saving 1 line
And since you're swapping in place, you don't need to return arr

your original array gets modified
function sortIt(items) {
    for (var i = items.length - 1; i >= 0; i--) {
        for (var j = items.length - i; j > 0; j--) {
            if (items[j] < items[j - 1]) {
                var tmp = items[j];
                items[j] = items[j - 1];
                items[j - 1] = tmp;
            }
        }
    }
}
abraham anak agung
@padunk
Mar 12 2018 05:16
@SweetCodingInc why is it iterating backwards is faster? And if nothing is return, it will get undefined right?
Markus Kiili
@Masd925
Mar 12 2018 06:31
@padunk It doesn't have to evaluate arr.length on each loop step. Usually you should not make such optimizations, and just try to write clean code.
abraham anak agung
@padunk
Mar 12 2018 06:33
@Masd925 Ooo. ok got that, thanks.
CamperBot
@camperbot
Mar 12 2018 06:33
padunk sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4722 | @masd925 |http://www.freecodecamp.org/masd925
Markus Kiili
@Masd925
Mar 12 2018 06:57
@padunk I tested it briefly on firefox, and it seems there is no difference in efficiency between forward and backward looping if you cache the array length like for(var i=0,l=arr.length;i<l;i++){}.
abraham anak agung
@padunk
Mar 12 2018 07:01
@Masd925 how you test it? how big the array?
Markus Kiili
@Masd925
Mar 12 2018 07:02
@padunk 100000 elements and 1000000 times iterated through.
abraham anak agung
@padunk
Mar 12 2018 07:46
@Masd925 hmmm... interesting. May i know how to do such performance test? i never done it before.
Markus Kiili
@Masd925
Mar 12 2018 07:49
@padunk For robust testing, you should use a benchmark page like jsperf.com. For testing on your own, you can use something like this on the javascript:
    var times = 1000000;

    var start = new Date().getTime();

    for (var i = 0; i < times; i++) {
        // Code to test
    }

    var end = new Date().getTime();
    var time = end - start;
    console.log("Executed code " + times + " times");
    console.log('Execution time: ' + time);
    console.log("Average time per execution: " + time/times);
abraham anak agung
@padunk
Mar 12 2018 07:55
@Masd925 cool. Thanks again. i want to test it against Array.sort
CamperBot
@camperbot
Mar 12 2018 07:55
padunk sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4723 | @masd925 |http://www.freecodecamp.org/masd925
Sweet Coding :)
@SweetCodingInc
Mar 12 2018 07:58
@padunk Array.prototype.sort will definitely be faster because the sorting algorithm you're using is bubble sort. The native sort method uses another algorithm called Merge Sort which is much more efficient than bubble sort
abraham anak agung
@padunk
Mar 12 2018 08:07
@SweetCodingInc wait i tought it was selection sort.
Markus Kiili
@Masd925
Mar 12 2018 08:08
@SweetCodingInc The algorithm that sort uses depends on the browser. They use on of several algorithms depending on the data type and data size.
Sweet Coding :)
@SweetCodingInc
Mar 12 2018 08:08
Mozilla/webkit uses Merge Sort
Always easier proving after looking at source
select jsarray.c link and go to line #800
Markus Kiili
@Masd925
Mar 12 2018 08:14
@SweetCodingInc Looks like merge sort variation that use insertion sort for small arrays?
At least HeapSort, MergeSort, and Insertion sorts are mentioned on the function names.
Sweet Coding :)
@SweetCodingInc
Mar 12 2018 08:47
@Masd925 Yeah.. After digging deeper into it, it turns out they're implementing a combination of merge sort and heap sort.
primarily using merge sort.
Need to dig around a little more to find out how they decide when to apply which sort
alpox
@alpox
Mar 12 2018 08:50
@SweetCodingInc this is kinda usual to do as different sort methods perform better on different sizes. Surely insertion sort is the fastest on small arrays (i think up to like 11 elements).
Sweet Coding :)
@SweetCodingInc
Mar 12 2018 08:52
yeah.. learning those optimization techniques is crucial :laughing:
alpox
@alpox
Mar 12 2018 09:09
When looking at the v8 engine on github i see that they use quicksort and insertiom sort
Insertion sort for elements from 2-10
Abdullah
@AbdullahChaudhry
Mar 12 2018 09:10
@alpox Native code?
alpox
@alpox
Mar 12 2018 09:10
For the rest, quicksort
Sweet Coding :)
@SweetCodingInc
Mar 12 2018 09:24
@alpox That code is just a punch in the face for all those one liner (and functional programming) fanatics :P
alpox
@alpox
Mar 12 2018 09:25
Of course there are different javascript engines. This is the sort implementation of v8, the one from mozilla might use heapsort instead as it seems
@SweetCodingInc ye well it depends on your goals
Sweet Coding :)
@SweetCodingInc
Mar 12 2018 09:25
what I mean is for pure performance, simple loops are best
alpox
@alpox
Mar 12 2018 09:26
Yes they are indeed
If i write for performance, i also opt for loops
Leigh Hobson
@leighhobson89
Mar 12 2018 10:23
var channelStatus = response.stream.channel.status.value; - is that a valid syntax for setting a variable to the getJSON response for the following JSON:
image.png
?
assume i have done the getJSON just above it sorry
Markus Kiili
@Masd925
Mar 12 2018 10:25
@leighhobson89 Why .value there ?
Leigh Hobson
@leighhobson89
Mar 12 2018 10:26
don't need that?
Markus Kiili
@Masd925
Mar 12 2018 10:26
Try removing it and log what you get.
Leigh Hobson
@leighhobson89
Mar 12 2018 10:26
i just wanted ot read in the string for status
ok
image.png
that works cheers,
Markus Kiili
@Masd925
Mar 12 2018 10:38
@leighhobson89 :+1:
Raghav Mundra
@Raghav17
Mar 12 2018 12:12
Hey, Can anyone please help me?
In my Pomodoro clock, the "Work" section clock is running and after it runs completely the "Break" section countdown starts, but after one complete iteration the clock isn't running again, can anyone please help me?
Alex
@alexandrupintilei
Mar 12 2018 13:04
image.png
Can someone help, and tell me why i cant kill that port with following command?
Thx
Blauelf
@Blauelf
Mar 12 2018 14:41
@alexandrupintilei Which application runs on port 4200?
Do you have the right to kill that one? (You might have to start your console explicitly with admin rights)
Alex
@alexandrupintilei
Mar 12 2018 14:49
@Blauelf i solve the problem. thx anyway
CamperBot
@camperbot
Mar 12 2018 14:49
alexandrupintilei sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4687 | @blauelf |http://www.freecodecamp.org/blauelf
Razvan Jackson
@RazvanJackson
Mar 12 2018 15:01
Someone who knows React?
alpox
@alpox
Mar 12 2018 15:13
@RazvanJackson :wave:
Jason Luboff
@JLuboff
Mar 12 2018 15:13
:wave:
alpox
@alpox
Mar 12 2018 15:13
@JLuboff :wave:
Jason Luboff
@JLuboff
Mar 12 2018 15:13
How's it going?
alpox
@alpox
Mar 12 2018 15:14
Hmm okayish i guess :D seldomly had to do such stuff i do now
And for you?
Jason Luboff
@JLuboff
Mar 12 2018 15:20
Not too bad. Monday morning.. stupid daylight savings time
alpox
@alpox
Mar 12 2018 15:21
daylight saving? :D Sitting inside? :D
Jason Luboff
@JLuboff
Mar 12 2018 15:23
Well.. sitting inside anyhow..but ya here we have daylight savings time. So twice a year, the time changes. In the spring, we move the clocks ahead one hour, and in the fall we set them back one hour. Stupid archaic time system
So now what was 7:23 AM, is 8:23 AM
alpox
@alpox
Mar 12 2018 15:24
Ah well that we sure have too :D but i never know when they change
Arturo Mago
@ArturoMago
Mar 12 2018 15:24
here too
Jason Luboff
@JLuboff
Mar 12 2018 15:24
Ah, wasn't sure if it was a worldwide thing or just US
alpox
@alpox
Mar 12 2018 15:26
I never heard someone call it daylight saving though :D
Jason Luboff
@JLuboff
Mar 12 2018 15:28
Us american's like to give names to everything :P
Norvin Burrus
@ndburrus
Mar 12 2018 15:29

@JLuboff :sparkles:

Most areas in North America and Europe, and some areas in the Middle East, observe daylight saving time (DST), while most areas of Africa and Asia do not. In South America, most countries in the north of the continent near the equator do not observe DST, while Paraguay and southern parts of Brazil do.

Adel
@AdelMahjoub
Mar 12 2018 15:30
I hate that hour changes
Jason Luboff
@JLuboff
Mar 12 2018 15:30
@ndburrus Well there we go! Thnaks
Norvin Burrus
@ndburrus
Mar 12 2018 15:30
@JLuboff :+1:
Adel
@AdelMahjoub
Mar 12 2018 15:31
They call it summer hour in EU
Must be something related to sorcerly
Jason Luboff
@JLuboff
Mar 12 2018 15:32
Summer hour. Psh.. just stop changing the damn time!
Adel
@AdelMahjoub
Mar 12 2018 15:33
there is a country or a town I forgot which is, near the usa, it has the same day twice
like that black cat glitch in matrix
It is Amon Ra calendar, definetly related to sorcerly muahahaha
Jason Luboff
@JLuboff
Mar 12 2018 15:34
Interesting
Adel
@AdelMahjoub
Mar 12 2018 15:35
then Gregorus II reused that calendar for the church
And then Hitler redifined timezones for europe, so he get the same hour in Berlin and Paris
and madrid
then php messed up all the timezones again ....
and here we go again
Jason Luboff
@JLuboff
Mar 12 2018 15:36
Don't talk about PHP, thats a disgusting word
Adel
@AdelMahjoub
Mar 12 2018 15:37
I'll refers to it as :elephant:
So maybe the actual ages are not accurate anymore
How you add an hour for 6months without any consequence ???
Jason Luboff
@JLuboff
Mar 12 2018 15:40
Magic
Adel
@AdelMahjoub
Mar 12 2018 15:40
:laughing: we maybe yonger than we expect
or older
and they say coffee is good for health
it is definetly not good
I'll use the star gate to get back in time, take some notes and come back
Ahmad Abdolsaheb
@ahmadabdolsaheb
Mar 12 2018 15:44
I heard coffee, who want some brownies to go with it ?
thanks @AdelMahjoub @JLuboff
CamperBot
@camperbot
Mar 12 2018 15:44
ahmadabdolsaheb sends brownie points to @adelmahjoub and @jluboff :sparkles: :thumbsup: :sparkles:
:cookie: 670 | @adelmahjoub |http://www.freecodecamp.org/adelmahjoub
:star2: 2364 | @jluboff |http://www.freecodecamp.org/jluboff
Adel
@AdelMahjoub
Mar 12 2018 15:45
the bot definitly not incrementing brownies
but no time to get back to the last message where I had 670
Jason Luboff
@JLuboff
Mar 12 2018 15:48
@AdelMahjoub Thanks
CamperBot
@camperbot
Mar 12 2018 15:48
jluboff sends brownie points to @adelmahjoub :sparkles: :thumbsup: :sparkles:
:cookie: 671 | @adelmahjoub |http://www.freecodecamp.org/adelmahjoub
Jason Luboff
@JLuboff
Mar 12 2018 15:49
Its incrementing :P You just wanted another brownie
Adel
@AdelMahjoub
Mar 12 2018 15:49
@JLuboff :laughing: I'll find the last 670 in the archives, I'm sure at some points it don't increment
Jason Luboff
@JLuboff
Mar 12 2018 15:51
:D
Jason Luboff
@JLuboff
Mar 12 2018 16:14
Arrgghh.. I love and hate promises :(
Blauelf
@Blauelf
Mar 12 2018 16:30
What's the best way to "cancel" a promise? Like I have Promise.race, how would I handle the promises that are active after the first one has resolved? Does this mean I cannot do complex things in those individual promises? Should I declare a "done" flag that they share?
Jason Luboff
@JLuboff
Mar 12 2018 16:33
Not positive on that. Would think you need to throw a return in there somewhere or some logic to handle it
Jason Luboff
@JLuboff
Mar 12 2018 17:36
@alpox ..around?
alpox
@alpox
Mar 12 2018 17:37
@JLuboff nope nope nope duck
Jason Luboff
@JLuboff
Mar 12 2018 17:37
Lies!
You mind if I send you a DM With another promise question? @alpox
alpox
@alpox
Mar 12 2018 17:38
@Blauelf cancelling is currently not in the promise specifications. Bluebird promises may have it implemented though
@JLuboff okay :)
Jason Luboff
@JLuboff
Mar 12 2018 17:39
@alpox Thanks..question incoming
CamperBot
@camperbot
Mar 12 2018 17:39
jluboff sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1585 | @alpox |http://www.freecodecamp.org/alpox
Abdullah
@AbdullahChaudhry
Mar 12 2018 17:39
@Blauelf Maybe look into Observables
alpox
@alpox
Mar 12 2018 17:39
@Blauelf to handle the ones which come after, you may need some additional state as you say
@AbdullahChaudhry observables sadly fill another gap than promises even though they can at times be used similar. Mostly they should not be used in the same scenarios though
Abdullah
@AbdullahChaudhry
Mar 12 2018 17:42
@alpox Reason I suggested that was because I think they can be cancelled. Or maybe the contexts are different
Will need to research this : )
Leigh Hobson
@leighhobson89
Mar 12 2018 17:43
hi guys, with the twitch.tv challenge, i'm 99% of the way to having it read the statuses correctly, but i think im using the wrong part of the getJSON to check if they are online. I am using if (<dataresponse>.stream) {} to evaluate if they are online or not. Is this the right way? It is returning nada for this property.
Jason Luboff
@JLuboff
Mar 12 2018 17:46
@leighhobson89 stream is correct, its either null if not streaming/offline or an object
Leigh Hobson
@leighhobson89
Mar 12 2018 17:48
thanks, so assuming my variables are set correctly when this executes, is this correct logic?
users.forEach(function(user) {
    $.getJSON(url + urlSection[1] + user[1]).then(function(response) {
      if (response.stream === null || response.stream === undefined) {
        channelStatus = 0; //offline
      }
      else {
        channelStatus = 1; //online
      }
(channelStatus is defined above in the function this call sits in)
Jason Luboff
@JLuboff
Mar 12 2018 17:51
@leighhobson89 I believe so
Leigh Hobson
@leighhobson89
Mar 12 2018 17:52
hmmppphh
cheers, ill have a think
alpox
@alpox
Mar 12 2018 17:52
@leighhobson89 you can make the if simpler with: if(!response.stream)
Gulsvi
@gulsvi
Mar 12 2018 17:53
I was just going to recommend the opposite :p
Leigh Hobson
@leighhobson89
Mar 12 2018 17:53
cheers @alpox
Gulsvi
@gulsvi
Mar 12 2018 17:53
if (response.stream) {
  channelStatus = 1; //online
}
else {
  channelStatus = 0; //offline
}
Was just searching what the best practice is - check for falsy or truthy first
Leigh Hobson
@leighhobson89
Mar 12 2018 17:55
iv implemented that by the by guys thanks, my situation is the same though in the end, the function is as follows...
function outputUsers(users, url, urlSection, selection) {

      //get the channel status
   var channelStatus = 0;
users.forEach(function(user) {
    $.getJSON(url + urlSection[1] + user[1]).then(function(response) {
      if (response.stream) {
        channelStatus = 1; //offline
      }
      else {
        channelStatus = 0; //online
      }
      $.getJSON(url + urlSection[0] + user[1]).then(function(data) { 
      var status = userStatus(channelStatus);
      user[0] = data.logo;
      if (selection == 0 && status !== "offlinestatus") {
        return;
      }
      else if (selection == 1 && status !== "onlinestatus")       {
        return;
      }
      stringParser(user, status);
    });
    });
  });
}
probably something to do with the line order knowing me
alpox
@alpox
Mar 12 2018 17:57
@gulsvi you can also go fancy: channelStatus = +!!response.stream just for the lulz
Gulsvi
@gulsvi
Mar 12 2018 17:57
lol :)
I did res[1].stream ? "online" : "offline" in mine
Leigh Hobson
@leighhobson89
Mar 12 2018 17:58
back in 20mins gotta pick the missus up from work lol
Gulsvi
@gulsvi
Mar 12 2018 17:58
I think when first writing that project, it helps to run a function based on the stream data - keep the code separate and outside of the getJSON to better analyze
if (response.stream) {
  processOnlineUsers();
}
else {
  processOfflineUsers();
}
Leigh Hobson
@leighhobson89
Mar 12 2018 18:14
Thats a good approach. Then just pass the appropriate values from each one into my functions further down the line which handle the outputting.
Chris
@ConnectCodes
Mar 12 2018 18:25
Hi guys, I am stuck in "Exact Change” challenge : Design a cash register drawer function checkCashRegister() that accepts purchase price as the first argument (price), payment as the second argument (cash), and cash-in-drawer (cid) as the third argument. Return change in coin and bills, sorted in highest to lowest order.
INot sure why I get an infinite loop. I made a while loop while(change !== 0) and under it I have series of if() to determine the right depeding on var change. Under each if there is another while(limit0 !==0) to keep adding that currency until there is nothing left. After each if statement I pushed curency name and value extracted to totalArray and return it. Not sure why I get two infinite loops and [“TWENTY”, very large number] instead of [“TWENTY”, 60].
https://codepen.io/Codeconnect/pen/dZQygY
Leigh Hobson
@leighhobson89
Mar 12 2018 18:34
@gulsvi thanks man, works a treat!
function outputUsers(users, url, urlSection, selection) {

users.forEach(function(user) {
    $.getJSON(url + urlSection[1] + user[1]).then(function(response) {
      if (response.stream) { //if online
        processOnlineUsers(user, url, urlSection, selection);
      }
      else {
        processOfflineUsers(user, url, urlSection, selection);
      }
    });
  });
}

function processOnlineUsers(user, url, urlSection, selection) {
  var status = "onlinestatus";
  $.getJSON(url + urlSection[0] + user[1]).then(function(data) { 
      user[0] = data.logo;
      if (selection == 0) {
        return; //skip if "Offline"
      }
      stringParser(user, status);
    });
}

function processOfflineUsers(user, url, urlSection, selection) {
  var status = "offlinestatus";
  $.getJSON(url + urlSection[0] + user[1]).then(function(data) { 
      user[0] = data.logo;
      if (selection == 1) {
        return; //skip if "Online"
      }
      stringParser(user, status);
    });
}
CamperBot
@camperbot
Mar 12 2018 18:34
leighhobson89 sends brownie points to @gulsvi :sparkles: :thumbsup: :sparkles:
:star2: 2664 | @gulsvi |http://www.freecodecamp.org/gulsvi
Leigh Hobson
@leighhobson89
Mar 12 2018 18:35
if i wanted to compress it back down, it would probably be a good idea to remove duplication, but for now, i wanna finish the project and get it working, ill refactor it at the end lol!
Stephen James
@sjames1958gm
Mar 12 2018 18:40
@ConnectCodes With floating point you might never reach exactly 0.
@ConnectCodes Or if the value is not a multiple of 20 you will go from > 0 to < 0 in one loop and never hit zero itself
Your loop probably should be while (value >= 20)
Chris
@ConnectCodes
Mar 12 2018 18:45
@sjames1958gm I understand so change !== 0 wont work. What do you mean by “Or if the value is not a multiple of 20 you will go from > 0 to < 0 in one loop and never hit zero itself"
Stephen James
@sjames1958gm
Mar 12 2018 19:00
@ConnectCodes if your value is not a multiple of 20, say 42, then it will go 42 -> 22 -> 2 -> -18 -> etc.
Jason Luboff
@JLuboff
Mar 12 2018 19:02
@alpox Thank you, here's some brownies
CamperBot
@camperbot
Mar 12 2018 19:02
jluboff sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1586 | @alpox |http://www.freecodecamp.org/alpox
Leigh Hobson
@leighhobson89
Mar 12 2018 19:12

in this function, whilst performing its business, is it possible to return the getJSON array 'data' back like this:

function processOnlineUsers(user, url, urlSection, selection) {
  var status = "onlinestatus";
  $.getJSON(url + urlSection[0] + user[1]).then(function(data) {
    user[0] = data.logo;
    if (selection == 0) {
      return; //skip if "Offline"
    }
    stringParser(user, status);
    return data;
  });
}

in order to receive it into an array like this:

var userData = [];
var userData = processOnlineUsers(user, url, urlSection, selection);
usersArray.push(userData);
Gulsvi
@gulsvi
Mar 12 2018 19:24
@leighhobson89 Short answer is no, because getJSON is asynchronous. You would need to ensure that the data has all come back from the server before pushing the data to your usersArray.
but don't get caught up in trying to do all of that, IMO. Just write the data to the page as you get it back from the server, otherwise, you're collecting data from the server, accessing that data to add it to a local variable, only to turn around and access it all over again.
Leigh Hobson
@leighhobson89
Mar 12 2018 19:35
thanks, well i already do that and it works a treat, im trying to do this to pull the data out into a place where i can add it to my search function. knowing that the user info has been called and already parsed out, i need to store it somewhere so i can do a filter on it and then tidyUp() and then reparse the new information using mky parseString() function - or is this the wrong approach?
is it better to tidyUp() and then re-perform the call each time keyUp runs on the search?
Chris
@ConnectCodes
Mar 12 2018 19:39

@sjames1958gm

ConnectCodes if your value is not a multiple of 20, say 42, then it will go 42 -> 22 -> 2 -> -18 -> etc. If I undertand correctly that means while loop wont work here or I do I need to change my condition. There aare too many if staements. I wanted to solve it useig some other method maybe reduce?

var used7 = 0;
                var limit7 = cid[7][1] *100;
            while(limit7 !==0){
                var unit7 = 2000;
                used7 += unit7;
                limit7 -= unit7;
                change -= unit7;
            }
            totalArray.push(["TWENTY", used7/100]);
Gulsvi
@gulsvi
Mar 12 2018 19:40
@leighhobson89 If you write the data to the page, it is stored for you in HTML. You can filter users based on a class name like "offline", or "online" and if you're trying to search for a user in the list, you could give each user div an ID equal to their user name and then filter based off of their ID. ($('[id*=' + searchTerm + ']')
Leigh Hobson
@leighhobson89
Mar 12 2018 19:46
thanks i will giove it some thought
Stephen James
@sjames1958gm
Mar 12 2018 19:51
@ConnectCodes You could use a fixed array of values of currency and use a loop over that array to drive the computation
Leigh Hobson
@leighhobson89
Mar 12 2018 20:47
I found this example for filtering @gulsvi and while it does the trick, my other elements in the row are not appearing - i am having some difficulty adapting it. this code converts the first screenshot in to the second (i didnt understand where to place the jquery selector you gave me in the code. the function is here and the screenshots:
 $("#search").on("keyup", function() {
    var value = $("#search").val().toLowerCase();
    $("#userheader div").filter(function() {
      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
    });
  });
image.png
image.png
i did succeed in giving each div an id of the username it represents however, so i would still prefer to implement this method if i could work out how
Gulsvi
@gulsvi
Mar 12 2018 20:49
@leighhobson89 from looking at the screenshots, I'm guessing that "#userheader div" does not select the entire div for that user. "channel info" remains after getting filtered out
Leigh Hobson
@leighhobson89
Mar 12 2018 20:50
it has an É´in it
sorry an 'e'
$("#userheader").append(
    "<div id='" + user[1].toLowerCase() + "' class='row justify-content-md-center userrecords'><div class='col-xs-3 thumbnail'><img src='" +
      user[0] +
      "' class='img-circle' alt='username placeholder'></img></div><div id='statusColumn' class='" +
      status +
      " col-xs-1'></div><div class='col-xs-8'><div class='row justify-content-md-center'>" +
      user[1] +
      "</div><div class='row justify-content-md-center'>Channel Info</div></div>"
  );
this is what i parse
Gulsvi
@gulsvi
Mar 12 2018 20:52
@leighhobson89 Use #userheader>div to only select the first div under #userheader instead of all
Leigh Hobson
@leighhobson89
Mar 12 2018 20:53
would that not take the other users out of the search though?
haha you're a genius
@gulsvi
thanks @gulsvi
CamperBot
@camperbot
Mar 12 2018 20:56
leighhobson89 sends brownie points to @gulsvi :sparkles: :thumbsup: :sparkles:
:star2: 2667 | @gulsvi |http://www.freecodecamp.org/gulsvi
Gulsvi
@gulsvi
Mar 12 2018 20:57
@leighhobson89 glad that worked - it was a bit of a guess without seeing all of your code
I think something like this could work well too:
  var value = $('#search').val().toLowerCase();
  $('.userrecords').show();
  $('.userrecords').not('[id*=' + value + ']').hide();
  $('.userrecords [id*=' + value + ']').show();
That's more along the lines of what I was hinting at earlier with this article: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors
Leigh Hobson
@leighhobson89
Mar 12 2018 21:03
ill try it - i just tried adding .row:first-child to the selector to see if it would search just by the name rather than a loose search returning info from everywhere in the div, as this is where only the user name is, but that screwed it up aswell - ill try this other way then decide which i like best
that does exactly what i just said i wanted - i will study what its doing a bit now, otherwise i wont be learning anything. cheers mate, thats exactly what i needed @gulsvi
i use selectors all day in my php scripts, but i just havent used them in jquery statements before, so it was hard to see how to place them, but now i can see
Brian
@BrianCodes33
Mar 12 2018 21:20

Use destructuring to obtain the length of the input string str, and assign the length to len in line.


function getLength(str) {
  "use strict";

  // change code below this line
  const length = 0; // change this
  // change code above this line

  return len; // you must assign length to len in line

}

console.log(getLength('FreeCodeCamp'));

confused on destructuring

Abdullah
@AbdullahChaudhry
Mar 12 2018 21:24
@BrianCodes33 Do you have a link to the original challenge
Abdullah
@AbdullahChaudhry
Mar 12 2018 21:25
@BrianCodes33 ty
CamperBot
@camperbot
Mar 12 2018 21:25
abdullahchaudhry sends brownie points to @briancodes33 :sparkles: :thumbsup: :sparkles:
:cookie: 40 | @briancodes33 |http://www.freecodecamp.org/briancodes33
Jason Luboff
@JLuboff
Mar 12 2018 21:38
That challenge makes no sense. They show you destructruring with an object...then give you a string?
Christopher McCormack
@cmccormack
Mar 12 2018 21:41
Agreed it's weird
Jason Luboff
@JLuboff
Mar 12 2018 21:42
@cmccormack Hey! How was the birthday?
Abdullah
@AbdullahChaudhry
Mar 12 2018 21:42
It's definitely a string that is being passed into the function, I console logged it
Christopher McCormack
@cmccormack
Mar 12 2018 21:42
@JLuboff :D awesome went to a Brazilian steakhouse, I love those places
Jason Luboff
@JLuboff
Mar 12 2018 21:43
@AbdullahChaudhry I know its a string being passed in. I'm just saying the challenge really doesn't make sense. They show you an example using an object but then give no objects in the actual challenge
@cmccormack Nice!
Christopher McCormack
@cmccormack
Mar 12 2018 21:45
@JLuboff Mostly spent the weekend working on my wife's parent's house, getting it ready for a sort of after wedding reception for the rest of the family to go to. How was your weekend?
Abdullah
@AbdullahChaudhry
Mar 12 2018 21:46
@JLuboff Yes I know that. I just used console log to check what is being passed to it as arguments
Jason Luboff
@JLuboff
Mar 12 2018 21:47
@cmccormack Good deal. It was alright. Errands and what not on Saturday... Sunday went to dinner with my grandpa and worked on getting some more stuff out of our old apartment into the new one
Christopher McCormack
@cmccormack
Mar 12 2018 21:48
This works but still doesn't pass:
function getLength(str) {
  "use strict";

  // change code below this line
  const { str: word } = { str }
  const len = word.length
  // change code above this line

  return len; // you must assign length to len in line

}

console.log(getLength('FreeCodeCamp'));
ohh didn't read the last comment
Gulsvi
@gulsvi
Mar 12 2018 21:49
length is a hidden property of an object, so it would be:
  const { length } = str; // change this
  const len = length;
fml, that doesn't work either lol
Christopher McCormack
@cmccormack
Mar 12 2018 21:50
@gulsvi yeah it did, almost
 const { length: len } = str
that solved it
I didn't think to just try destructuring str as an object. The last comment requires reassignment from length to len
Abdullah
@AbdullahChaudhry
Mar 12 2018 21:51
@cmccormack Well done man. Thanks
CamperBot
@camperbot
Mar 12 2018 21:51
abdullahchaudhry sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1376 | @cmccormack |http://www.freecodecamp.org/cmccormack
Gulsvi
@gulsvi
Mar 12 2018 21:52
Nice job @cmccormack :) thanks!
thanks @cmccormack
CamperBot
@camperbot
Mar 12 2018 21:52
gulsvi sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1377 | @cmccormack |http://www.freecodecamp.org/cmccormack
Christopher McCormack
@cmccormack
Mar 12 2018 21:52
@JLuboff I forgot you were moving sorry I didn't help :grin:
Jason Luboff
@JLuboff
Mar 12 2018 21:54
@cmccormack All good. We had moved the weekend before but I'm sure you know how that goes...takes a while to unpack and still have some stuff at the old place
Christopher McCormack
@cmccormack
Mar 12 2018 21:54
Yeah - moving truly does suck. The only good part is purging if you give yourself time
Jason Luboff
@JLuboff
Mar 12 2018 21:55
Probably need to purge a whole lot more than we have :joy:
Christopher McCormack
@cmccormack
Mar 12 2018 21:56
FCC beta is kind of buggy (duh) - trying to log in using Github: We could not find a user by the name of "github"
Jason Luboff
@JLuboff
Mar 12 2018 21:56
Can you even log into beta? I had tried in the past and it wouldn't let me so I gave up
Christopher McCormack
@cmccormack
Mar 12 2018 21:57
@JLuboff I read The Life-Changing Magic of Tidying Up: The Japanese Art of Decluttering and Organizing a while back and now I'm always trying to find ways to purge stuff
Nope I've not been able to log into beta for probably 9 months
Jason Luboff
@JLuboff
Mar 12 2018 21:57
I may have to give that book a read
Christopher McCormack
@cmccormack
Mar 12 2018 21:58
Summary - if things don't give you joy when you're holding it, get rid of it.
Jason Luboff
@JLuboff
Mar 12 2018 21:58
Touche
Abdullah
@AbdullahChaudhry
Mar 12 2018 21:58
@cmccormack Did you get the shits? lol
Christopher McCormack
@cmccormack
Mar 12 2018 21:59
@AbdullahChaudhry XD
Abdullah
@AbdullahChaudhry
Mar 12 2018 21:59
@cmccormack In that book, she describes how some people will get the shits after they have done a full clean up. LOL.
Christopher McCormack
@cmccormack
Mar 12 2018 21:59
haha I don't remember that, was it a good or a bad thing?
Abdullah
@AbdullahChaudhry
Mar 12 2018 22:00
Somehow, cleaning your external environment triggers the cleanup of your internal environment
I dunno I do remember reading something about that, read that book briefly ages ago
Christopher McCormack
@cmccormack
Mar 12 2018 22:02
Hmm I usually glazed over anything that sounded pseudosciency.
Sometimes you have to take the good with the bad :D
Abdullah
@AbdullahChaudhry
Mar 12 2018 22:02
I know someone that went through that.....
Gulsvi
@gulsvi
Mar 12 2018 22:03
It's true - lots of people have claimed it causes a "detox" of sorts
Probably from 10-year old mold spores hiding out between all the junk you clean up, but...anyway... back to JS :)
Christopher McCormack
@cmccormack
Mar 12 2018 22:04
Haha how dare you try to get this room back on track @gulsvi
Abdullah
@AbdullahChaudhry
Mar 12 2018 22:04
lol
Gulsvi
@gulsvi
Mar 12 2018 22:05
¯\_(ツ)_/¯
Brian
@BrianCodes33
Mar 12 2018 22:31

const LOCAL_FORECAST = {
  today: { min: 72, max: 83 },
  tomorrow: { min: 73.3, max: 84.6 }
};

function getMaxOfTmrw(forecast) {
  "use strict";
  // change code below this line
  const maxOfTomorrow = undefined; // change this line
  // change code above this line
  return maxOfTomorrow;
}

console.log(getMaxOfTmrw(LOCAL_FORECAST)); // should be 84.6
Use destructuring assignment to obtain max of forecast.tomorrow and assign it to maxOfTomorrow.
Leigh Hobson
@leighhobson89
Mar 12 2018 22:33

This works, but I presume theres a better way to change color of menu items (which are divs not list items in my case):

$("#all").on("click", function() {
    selectMenuItem(2);
    tidyUp();
    outputUsers(users, url, urlSection, 2);
  });

  $("#online").on("click", function() {
    selectMenuItem(1);
    tidyUp();
    outputUsers(users, url, urlSection, 1);
  });

  $("#offline").on("click", function() {
    selectMenuItem(0);
    tidyUp();
    outputUsers(users, url, urlSection, 0);
  });

which calls:

function selectMenuItem(menu) {
  switch (menu) {
    case 0:
      $("#all").removeClass("menuselected");
      $("#online").removeClass("menuselected");
      $("#all").addClass("menu"); 
      $("#online").addClass("menu");
      $("#offline").removeClass("menu"); 
      $("#offline").addClass("menuselected");
    break;
    case 1:
      $("#all").removeClass("menuselected");
      $("#offline").removeClass("menuselected");
      $("#all").addClass("menu"); 
      $("#offline").addClass("menu");
      $("#online").removeClass("menu"); 
      $("#online").addClass("menuselected");
    break;
    case 2:
      $("#online").removeClass("menuselected");
      $("#offline").removeClass("menuselected");
      $("#online").addClass("menu"); 
      $("#offline").addClass("menu");
      $("#all").removeClass("menu"); 
      $("#all").addClass("menuselected");
    break;
  }
}
Gulsvi
@gulsvi
Mar 12 2018 22:46
@leighhobson89 You can use chaining to clean it up a little, like for case 0:
      $("#all, #online").removeClass("menuselected").addClass("menu"); 
      $("#offline").removeClass("menu").addClass("menuselected");
Might as well move your tidyUp() and outputUsers() calls to the selectMenuItem function too unless there are times you will call selectMenuItem without calling tidyUp() and ouptutUsers()
Leigh Hobson
@leighhobson89
Mar 12 2018 22:49
thanks a lot, chaining, theres a novel idea!
@gulsvi thanks
CamperBot
@camperbot
Mar 12 2018 22:49
leighhobson89 sends brownie points to @gulsvi :sparkles: :thumbsup: :sparkles:
:star2: 2668 | @gulsvi |http://www.freecodecamp.org/gulsvi
Gulsvi
@gulsvi
Mar 12 2018 22:56
Happy to help again!
@BrianCodes33 What's the question, or did you solve it?