These are chat archives for FreeCodeCamp/HelpJavaScript

21st
Nov 2018
Jason Luboff
@JLuboff
Nov 21 2018 01:51
@bradtaniguchi this is true lol. Not even an issue that I could see...sounds like a browser issue (cache maybe..)
Brad
@bradtaniguchi
Nov 21 2018 01:52
@JLuboff It was a change I found with one of the @type packages for typescript, they changed the types on a minor version change that affected like 100 files. Had to revert, and I opened an issue since it broke a lot of my stuff
Tom
@moT01
Nov 21 2018 01:59
:heavy_check_mark:
troncarter
@troncarter
Nov 21 2018 02:18
i installed request-promise without first installing requests on node. do i just instal requests and then reinstall request-promise ?
Brad
@bradtaniguchi
Nov 21 2018 02:19
@troncarter You should be able to install both at any time. How exactly are you "installing" the packages to be exact?
troncarter
@troncarter
Nov 21 2018 02:19
npm
Brad
@bradtaniguchi
Nov 21 2018 02:21
Yea, whats the commands your running, are you saving the dependencies? Did you have any errors, or just curious?
troncarter
@troncarter
Nov 21 2018 02:25
saving the dependencies? what do you mean?
Brad
@bradtaniguchi
Nov 21 2018 02:32
are you running npm install --save request-promise
troncarter
@troncarter
Nov 21 2018 02:39
what does that do?
is it because I didn't do init?
Brad
@bradtaniguchi
Nov 21 2018 02:41
save it to your package.json. I recommend looking into a getting started guide with npm and nodejs, like this one: https://codeburst.io/getting-started-with-node-js-a-beginners-guide-b03e25bca71b
Sounds like you already installed node+npm so you can skip those steps.
Unless you plan on your code being a quick script or a "sandbox" where you just wanna try something out real-quick I recommend making a package.json (using npm init). Depending on how you work you might want to add other stuff to (like git, eslint, formatters, etc)
troncarter
@troncarter
Nov 21 2018 02:43
thanks
Karma Drukpa
@coderkarma
Nov 21 2018 02:43
Hello
troncarter
@troncarter
Nov 21 2018 02:43
so npm init is not necessary?
Karma Drukpa
@coderkarma
Nov 21 2018 02:43
I need help on this one
while sorting
Brad
@bradtaniguchi
Nov 21 2018 02:58
@troncarter Nope, but odds are you would want it, since it keeps track of the dependencies your using. Without it your need to manually go over your code to see, and if you delete node_modules you have to install all of them manually again.
Finally, if you upload your code to git you don't want to upload node_modules since its massive
@coderkarma Post your code (if its small) and see if someone can help
I'm heading out for a bit, might be back on
Karma Drukpa
@coderkarma
Nov 21 2018 03:01
you heading out now?
Aditya
@ezioda004
Nov 21 2018 03:05
@coderkarma Help with what?
troncarter
@troncarter
Nov 21 2018 03:09
im not sure im installing my node packages properly
Claudio Restifo
@Marmiz
Nov 21 2018 03:23

@troncarter npm init is to initilise a project.
npm install is to install packages.

Have a look at the available cli commands for further reference

Karma Drukpa
@coderkarma
Nov 21 2018 03:45
@ezioda004
const capitalsFirst = (str) => {
  // split the string in the word arr of word
  // loop through arr
  // check the assi value of each first letter of the word
  // sort asci value in decending order


  let words = str.split(' ');
   for (let i = 0; i < words.length; i++){
    let word = words[i];
     //console.log(word[0].charCodeAt());// 104 89 83 109 65
         word[0].sort((a,b) => { return b -a })
      // I am trying to sort the charcter in  decending order but this doesn't seem working.
    }

  }

capitalsFirst("hey You, Sort me Already!"); //, "You, Sort Already! hey me")
Aditya
@ezioda004
Nov 21 2018 03:48

@coderkarma Dont use for loop and sort together, since sort is a loop itself. First you should solve this case:

If a word starts with a number or special character, skip the word and leave it out of the result.

After that, checkout .charCodeAt()
Karma Drukpa
@coderkarma
Nov 21 2018 03:50
oh okay, i was using for loop and sort together .
troncarter
@troncarter
Nov 21 2018 04:22
does FCC still have the progress page with the calender?
Victor Popescu
@VicPopescu
Nov 21 2018 06:08
@troncarter https://www.freecodecamp.org/settings, then Show me my public portfolio
iamSubhoKarmakar
@iamSubhoKarmakar
Nov 21 2018 07:41
What is babel preset
What is babel preset stage -0,1,2,3
Adel
@AdelMahjoub
Nov 21 2018 07:43
CarlW
@ugglr
Nov 21 2018 07:45
@AdelMahjoub aha! alright thank you for teaching me this, that was new for me
I'm coming from Java where the return breaks the loop
Aditya
@ezioda004
Nov 21 2018 07:46
@iamSubhoKarmakar Stages are the proposal stages - these are not JS standard feature, but maybe added in the future.
Adel
@AdelMahjoub
Nov 21 2018 07:47
@ugglr yw, check mdn often, valuable ressource
iamSubhoKarmakar
@iamSubhoKarmakar
Nov 21 2018 07:49
Thanks @AdelMahjoub @ezioda004
Sujit
@sujitworx
Nov 21 2018 09:18
Hey Guys, wanted to some help with this problem in basic algorithm scripting. Basically, I need to return an array containing all the largest numbers in 4 sub-arrays
function largestOfFour(arr) {
  // You can do this!
  let maxArr = []
  let maxNumber = 1
  for(let i=0; i<arr.length - 1; i++) {
    if (arr[i] > maxNumber) {
      maxArr.push(arr[i])
    }
    return maxArr
  }
  arr = maxArr
  return arr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
is the approach wrong in it's entirety or is it correct and can be impoved upon to access just about each element in the subarrays?
Claudio Restifo
@Marmiz
Nov 21 2018 09:36

@sujitmohanty well two main things:
1 - you have array of arrays, so arr[0] (for example) is [4,5,1,3]; you probably want to access the values inside because

if (arr[i] > maxNumber) // [4,5,1,3] > 1

doesn't make much sense.

2 - if you return in a loop, it will stop its execution so for example

let arr = [];
for(let i = 0; i < 10; i++) {
  arr.push(i)
  return arr;
}

console.log(arr) // [0] and not [0, 1, 2, .... 10]

Hope it helps :+1:

Sujit
@sujitworx
Nov 21 2018 09:40
ok. thanks!
"Talk about a cache flow problem: This JavaScript can snoop on other browser tabs to work out what you're visiting
Yes, even the Tor browser can be spied on by this nasty code"
Simon Cordova
@gbsimon87
Nov 21 2018 15:42
Hey all :)
Pagnito
@Pagnito
Nov 21 2018 18:01
i have a really weird problem
var location = document.querySelector('#location');
some how results in
Screen Shot 2018-11-21 at 1.02.06 PM.png
Simon Cordova
@gbsimon87
Nov 21 2018 18:02
Is that in a React app?
Pagnito
@Pagnito
Nov 21 2018 18:02
nah
the crazy part is this
<div class="input-section mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
            <input class="mdl-textfield__input" type="text" id="title">
            <label class="mdl-textfield__label" for="title" name="title">Title</label>
          </div>
          <div class="input-section mdl-textfield mdl-js-textfield mdl-textfield--floating-label" id="manual-location">
            <input class="mdl-textfield__input" type="text" id="location">
            <label class="mdl-textfield__label" for="location" name="location">Location</label>
          </div>
when i try to access the title input, im fine, but location...nop
i removed the the class and it seems to work
Simon Cordova
@gbsimon87
Nov 21 2018 18:08
what does console login location bring?
Perhaps its define elsewhere in the global?
logging**
Brad
@bradtaniguchi
Nov 21 2018 18:10
my guess is the way the JS is using the location isn't working as expected
since the url turns into an "html object"
Simon Cordova
@gbsimon87
Nov 21 2018 18:14
Mine as well, the location object on the window object?
Adel
@AdelMahjoub
Nov 21 2018 18:41
better use another name than location
Simon Cordova
@gbsimon87
Nov 21 2018 18:50
Good point - I know it's initially assigned, but as per the code above it seemed like a reassignment, I'd have assumed it would now contain that new value, but perhaps not by the time called
Adel
@AdelMahjoub
Nov 21 2018 18:57
why the label has the name attribute instead of the input field ?
mdn says it is a read-only property
Jason Luboff
@JLuboff
Nov 21 2018 19:11
@bradtaniguchi so after thinking some more about the issue I mentioned yesterday...pretty sure it’s user error. I have it show 15 items per page...they had 18 items meaning 2 pages worth. Don’t think they went to the second page or used the sort/filter options
Brad
@bradtaniguchi
Nov 21 2018 19:12
@JLuboff You sure you were talking to me about this issue? I don't remember talking about it haha, but then my memories bad
Brad
@bradtaniguchi
Nov 21 2018 19:58
Ah back to Angular code... with the insight I've gained from backend, I see the benefits of this stuff
Jason Luboff
@JLuboff
Nov 21 2018 20:16
@bradtaniguchi in reference to me having checked shit based on an email
Pagnito
@Pagnito
Nov 21 2018 20:59
oooh i cant wait til periodic syncin get supported
Brad
@bradtaniguchi
Nov 21 2018 21:05
Ah I see