These are chat archives for FreeCodeCamp/HelpJavaScript

22nd
Feb 2018
Brian
@BrianCodes33
Feb 22 2018 01:38
any ideas here?
input:
   [[ 0, 1, 2, 3, 4 ],
    [ 10,11,12,13,14 ],
    [ 20,21,22,23,24 ],
    [ 30,31,32,33,34 ]] 

output:
     '0,1,2,3,4\n'
    +'10,11,12,13,14\n'
    +'20,21,22,23,24\n'
    +’30,31,32,33,34
function toCsvText(array) {
   for(var i=0; i<array.length; i++) {
      console.log(array[i])
    }
}
Brad
@bradtaniguchi
Feb 22 2018 01:42
@BrianCodes33 That's not csv right? its just an array of array of numbers?
Brian
@BrianCodes33
Feb 22 2018 01:43
right my goal is to turn it into csv
function toCsvText(array) {
   for(var i=0; i<array.length; i++) {
      console.log(array[i].join('\n'))
    }
}
?
Brad
@bradtaniguchi
Feb 22 2018 01:47
@BrianCodes33 You should just return the array you want and print that out, to help in debugging, instead of printing the stuff. The output you get looks funny, is that the real output?
Or is that what you actually want, or you what is that>
Brian
@BrianCodes33
Feb 22 2018 01:50
no thats the expected output
Brad
@bradtaniguchi
Feb 22 2018 01:51
With all the +, \nand commas?
@BrianCodes33
Pieter Stokkink
@forkerino
Feb 22 2018 06:32
@BrianCodes33 did you already find an answer? I think using .map on the outer array is a good way to approach this.
Markus Kiili
@Masd925
Feb 22 2018 06:33
@forkerino Morning.
Pieter Stokkink
@forkerino
Feb 22 2018 06:35
@Masd925 Good morning! How are things?
Brad
@bradtaniguchi
Feb 22 2018 06:36
@forkerino Yea He figured it out :)
Pieter Stokkink
@forkerino
Feb 22 2018 06:36
Ok
Markus Kiili
@Masd925
Feb 22 2018 06:37
@forkerino Fine. Got my knee support today, so maybe back to wrestling this week.
How about you?
Pieter Stokkink
@forkerino
Feb 22 2018 06:38
My gf is doing krav maga these days and she showed me some exercises last night. Today I feel like having more muscles in my body than I knew of.
Other than that, I'm well. We are finally maybe having something that resembles winter here the coming week
Markus Kiili
@Masd925
Feb 22 2018 06:40
@forkerino We have like -20 C here, so winter is coming.
Pieter Stokkink
@forkerino
Feb 22 2018 06:41
We have frost at night!
Will touch -7 over the weekend, but days will still be around or above 0
Can't remember the last time we could skate, but perhaps next week!
Aftab Parvez
@aftabparvez
Feb 22 2018 09:57
Hi everyone! I’m unable to change the values of lat and long which are defined outside of the scope of the navigator function. Here’s the code
function url () {

    var lat = 0;
    var long = 0; 

    navigator.geolocation.getCurrentPosition(function (val){
        lat = Math.round(val.coords.latitude);
        long = Math.round(val.coords.longitude); 
    });

    console.log ("https://fcc-weather-api.glitch.me/api/current?lat="+ lat +"&lon="+ long);
};

url();
Markus Kiili
@Masd925
Feb 22 2018 09:58
@aftabparvez Those variables get values at some point later when the geolocation response comes. That is after that script has finished executing.
Aftab Parvez
@aftabparvez
Feb 22 2018 09:58
Console gives the output of https://fcc-weather-api.glitch.me/api/current?lat=0&lon=0
Daniel Romero
@Ranacode
Feb 22 2018 09:58
where is the position object?
Markus Kiili
@Masd925
Feb 22 2018 09:59
@aftabparvez A basic solution is to either use those coordinates inside the callback function, or call a function there and pass coordinates as arguments.
Aftab Parvez
@aftabparvez
Feb 22 2018 10:00
@Ranacode Whoops! I was reading something on Stack overflow which suggested that I use objects.. I’ve changed the code to the original version in which only used numbers.
Daniel Romero
@Ranacode
Feb 22 2018 10:00
Well you can just get the lat and latitude values inside one function an return them into an object , then you can use that object into another function that makes the api call
Markus Kiili
@Masd925
Feb 22 2018 10:03
@aftabparvez The basic logic is that only inside the callback function you know that the response has come and you need to make things happen there.
Aftab Parvez
@aftabparvez
Feb 22 2018 10:04
@Masd925 You are right.. There’s a delay in getting the values back when I run this
navigator.geolocation.getCurrentPosition(function (val){
        lat = Math.round(val.coords.latitude);
        console.log(lat);
        long = Math.round(val.coords.longitude); 
        console.log(long);
    });
@Masd925 I’m new to this and I’m having a hard time wrapping my head around how to get the values updated.. If you don’t mind could you give me an example of how to do this here…

@Ranacode Do you mean something like this ```
function url () {

var position = {lat: 0, long: 0}; 

navigator.geolocation.getCurrentPosition(function (val){
    position.lat = Math.round(val.coords.latitude);
    position.long = Math.round(val.coords.longitude); 
});

console.log ("https://fcc-weather-api.glitch.me/api/current?lat="+ position.lat +"&lon="+ position.long);

};

url(); ```

Unfortunately, this is also resulting in the same output - https://fcc-weather-api.glitch.me/api/current?lat=0&lon=0
Markus Kiili
@Masd925
Feb 22 2018 10:09
navigator.geolocation.getCurrentPosition(function(position){
   var lat = Math.round(val.coords.latitude);
   var long = Math.round(val.coords.longitude);  
   console.log(lat,lon); // you can do things here with the response data or call a function that does
   doOtherStuff(position);
});

function doOtherStuff(pos) {
  //...
}
@aftabparvez
Using global variables or objects doesn't really help here.
Aftab Parvez
@aftabparvez
Feb 22 2018 10:14

@Masd925 Thank you!!!!!! I modified it like this ```
function url () {

var lat = 0;
var long = 0;

navigator.geolocation.getCurrentPosition(function (val){
    lat = Math.round(val.coords.latitude);
    long = Math.round(val.coords.longitude); 
    console.log ("https://fcc-weather-api.glitch.me/api/current?lat="+ lat +"&lon="+ long);
});

};

url();
```

CamperBot
@camperbot
Feb 22 2018 10:14
aftabparvez sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4700 | @masd925 |http://www.freecodecamp.org/masd925
Aftab Parvez
@aftabparvez
Feb 22 2018 10:15
@Masd925 I’ve also changed the variables to be declared inside the getCurrentPosition function - navigator.geolocation.getCurrentPosition(function (val){ var lat = Math.round(val.coords.latitude); var long = Math.round(val.coords.longitude); console.log ("https://fcc-weather-api.glitch.me/api/current?lat="+ lat +"&lon="+ long); });
@Ranacode I got what you were saying now… :-) Thank you!!
CamperBot
@camperbot
Feb 22 2018 10:19
aftabparvez sends brownie points to @ranacode :sparkles: :thumbsup: :sparkles:
:cookie: 363 | @ranacode |http://www.freecodecamp.org/ranacode
Kelechi Chinaka
@ke1echi
Feb 22 2018 13:55
function remove(s){
  s = s.split` `;
  for (let i = 0, n = s.length; i < n; i++) {
    while (s[i].endsWith('!')) {
      s[i] = s[i].slice(0,s[i].length);
    }
  }
  return s;
}
code times out.. what am i doing wrong
remove("Hi! Hi!") => "Hi Hi")
Stephen James
@sjames1958gm
Feb 22 2018 13:56
@kelechy Well your call to split is missing ()
@kelechy You should console.log values to see what they contain when code is acting up
Kelechi Chinaka
@ke1echi
Feb 22 2018 13:57
@sjames1958gm the split is not the issue. that valid js syntax
it times out so i cant see the console message @sjames1958gm
Kelechi Chinaka
@ke1echi
Feb 22 2018 14:06
can i send you the kata link? @sjames1958gm
Stephen James
@sjames1958gm
Feb 22 2018 14:19
@kelechy Sure
s = s.split` `;
s = split(' ');
Nazar
@IsaakNazar
Feb 22 2018 14:36
why the code throws an error Uncaught TypeError: skipButtons.forEach is not a function
const skipButtons = document.querySelector('[data-skip]');
skipButtons.forEach(button => button.addEventListener('click', skip));
Kelechi Chinaka
@ke1echi
Feb 22 2018 14:38
oh Christ i was doing slice(0,s[i].length) instead of slice(0,s[i].length-1) @sjames1958gm
Stephen James
@sjames1958gm
Feb 22 2018 14:38
@IsaakNazar querySelector doesn't return a collection querySelectorAll does
@kelechy Ah.
Kelechi Chinaka
@ke1echi
Feb 22 2018 14:39
function remove(s){
  s = s.split` `;
  for (let i = 0, n = s.length; i < n; i++) {
    while (s[i].endsWith('!')) {
      s[i] = s[i].slice(0,s[i].length-1);
    }
  }
  return s.join``;
}
Nazar
@IsaakNazar
Feb 22 2018 14:40
@sjames1958gm Thanx :)
CamperBot
@camperbot
Feb 22 2018 14:40
isaaknazar sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 9018 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Stephen James
@sjames1958gm
Feb 22 2018 14:42
@kelechy Does that work?
return s.split(' ').map((e) => e.replace(/!*$/, '')).join(' ') here is my code
@kelechy Your join should use space
Kelechi Chinaka
@ke1echi
Feb 22 2018 14:44
yea, i need to fix space @sjames1958gm
Stephen James
@sjames1958gm
Feb 22 2018 14:45
@kelechy When you have an array and want to convert each element - think .map
Kelechi Chinaka
@ke1echi
Feb 22 2018 14:46
yea but i always have issue of specifying the index
how do i specify the lsat index using .map @sjames1958gm
Stephen James
@sjames1958gm
Feb 22 2018 14:46
@kelechy The second parameter to the callback is the index of the current element.
@kelechy The map would be replacing your for loop not your while loop
Kelechi Chinaka
@ke1echi
Feb 22 2018 14:50
ok i'll do with a for and .map()
FlashHero
@FlashHero
Feb 22 2018 17:31
How do mongoDB and redux go together, please provide an example or refer me to any resources
Jason Luboff
@JLuboff
Feb 22 2018 17:38
I haven't used redux before, but you would use MongoDB to store your data and using your backend to access it and send it to the frontend
Josh
@jknapp25
Feb 22 2018 17:43
sorry, screwed up that markdown
this just returns a "0" in the place of where it should be in my container
FlashHero
@FlashHero
Feb 22 2018 17:53
@JLuboff so redux is useless when using a database ?
Jason Luboff
@JLuboff
Feb 22 2018 17:54
@FlashHero I have never worked with, let alone looked at, redux. I don't see why you wouldn't be able to but again I know nothing of it
FlashHero
@FlashHero
Feb 22 2018 17:58
@JLuboff ok thanks
CamperBot
@camperbot
Feb 22 2018 17:58
flashhero sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2341 | @jluboff |http://www.freecodecamp.org/jluboff
Gulsvi
@gulsvi
Feb 22 2018 18:08
@jknapp25 You can edit your posts in Gitter and delete them too. This room is for help with Free Code Camp's Javascript Algorithm Challenges, so you might get better help elsewhere.
Josh
@jknapp25
Feb 22 2018 18:10
@gulsvi ahh okay, do you have any suggestions?
alpox
@alpox
Feb 22 2018 18:14
@FlashHero redux is designed for holding all your state at one place for GUI applications. That only has to do with a database so far as the data which goes into the redux store comes usually partly from the database .)
But so mongodb would be used on the backend and redux on the frontend
Gulsvi
@gulsvi
Feb 22 2018 18:26
@jknapp25 No
Jason Luboff
@JLuboff
Feb 22 2018 18:56
Sure is exciting when your code works.. :joy:
FlashHero
@FlashHero
Feb 22 2018 20:34
@alpox so pass data to redux from back-end and modify the data and update the redux store and push it to the mongoDB?
alpox
@alpox
Feb 22 2018 21:06
@FlashHero Before you go to use redux, better learn about how to use react without it
Redux is just an alternative solution for state management apart from the state management system frameworks already have integrated
The only reason Redux exists is because state is usually scattered all over the components and the state and the eventhandlers to change it have to passed through multiple levels of components to make it work like it should. Redux solves that problem with collecting all application state in one place and "inject" it into the components which need it.
So redux makes sense to use in big applications where you would run into that issue of scattered state which has to be shared by many child components down the tree
Brad
@bradtaniguchi
Feb 22 2018 21:16
@alpox I don't know much about redux, but what you just said helped me understand its use case better. Thanks
CamperBot
@camperbot
Feb 22 2018 21:16
bradtaniguchi sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1546 | @alpox |http://www.freecodecamp.org/alpox
alpox
@alpox
Feb 22 2018 21:19
@bradtaniguchi You're welcome :)
Kaz Baig
@kbaig
Feb 22 2018 22:43
Anyone used react-transition-group?
Jason Luboff
@JLuboff
Feb 22 2018 22:43
@kbaig NO
Kaz Baig
@kbaig
Feb 22 2018 22:43
:(
Jason Luboff
@JLuboff
Feb 22 2018 22:43
:D
@kbaig What's crackin'?
Kaz Baig
@kbaig
Feb 22 2018 22:45
Trying to create mounting/dismounting animations for search results in React
Trying to put finishing touches to refactoring this https://codepen.io/kbaig/pen/zNrqwz
I've got the mounting animation done but the dismount is proving challenging
Jason Luboff
@JLuboff
Feb 22 2018 22:47
Oh ya there it goes
FlashHero
@FlashHero
Feb 22 2018 23:27
@alpox I thought Redux was meant to work like a database? I'm still confused, so you're supposed to use Redux just for front-end state management in react, and it has nothing to do with the actual mongoDB because that's handled in the back-end ?
alpox
@alpox
Feb 22 2018 23:35
@FlashHero redux is not intended to be a database and also does not work like one at all. You dont have to use it with react, you can also use it with other frameworks like angular, but its most often used in conjunction with react.
And yes it has nothing to do with mongodb
Brad
@bradtaniguchi
Feb 22 2018 23:45
@FlashHero There's different levels of state, for example typing into gitter exists as just client-state until you hit submit, which is then sent the database, so now its part of two state areas. Then it gets sent to you (and everyone else) to be part of their client state. The client-state management is what redux handles. You could hold state between all your components, but most of the time people find it easier to use redux
(I'm an Angular guy, we use services and components in the same way.)