These are chat archives for FreeCodeCamp/HelpJavaScript

15th
Jan 2018
DistinctWolf
@DistinctWolf
Jan 15 2018 01:17
@gothamknight ok thanks
CamperBot
@camperbot
Jan 15 2018 01:17
flashhero sends brownie points to @gothamknight :sparkles: :thumbsup: :sparkles:
:cookie: 482 | @gothamknight |http://www.freecodecamp.org/gothamknight
Stephen James
@sjames1958gm
Jan 15 2018 02:47
@Mariciano95 If you want to look at improving there is the .every function on arrays
DistinctWolf
@DistinctWolf
Jan 15 2018 02:48
is Codepen embedding free and do i have to cite them ?
Alexander Køpke
@alexanderkopke
Jan 15 2018 03:01
a
Tom
@moT01
Jan 15 2018 03:48
@FlashHero yes, its free - pretty sure they site themselves
https://s.codepen.io/moT01/pen/vgOaoJ - did it on my portfolio
aRtoo
@artoodeeto
Jan 15 2018 05:17

hello guys how do you get the values of a cell in a table in vanilla javascript?

<table id="myTable">
  <tr>
    <td id="uno">HELLO</td>
    <td>HI</td>
  </tr>
</table>

this doesnt work. document.getElementById('uno').value

Claudio Restifo
@Marmiz
Jan 15 2018 05:42
use innerText or innerHtml instead of value
aRtoo
@artoodeeto
Jan 15 2018 07:27

hello guys im doin my tictactoe but on this part of the code is not working

function checkGame() {

    //loops thru the winCombo array of arrays
    for (var i=0; i<winCombo.length; i++) {
        for (var j=0; j<winCombo[i].length; j++) {
            //takes the values or text of the cells 
            var uno = document.getElementById(winCombo[i][0]).textContent;
            var dos = document.getElementById(winCombo[i][1]).textContent;
            var tres = document.getElementById(winCombo[i][2]).textContent;

            //if theres no text on each cells
            if (uno === '' && dos === '' && tres === '') {
                break;
            } 
            //checks if the variables have the same text value
            else if (uno === dos && uno === tres) {
                  //if true remove the eventlistener then alart a winner
                  console.log('this will show if the condtion is true but loop is not working');  
                  for(var c=0; c<cells.length; c++) 
                    {  
                        cells[c].removeEventListener('click', function(){
                            alert('shit!!!!')
                        });
                    }
            }
        }
    }
}

but the console.log is show and the for loop to remove the event is not working.
heres the pen https://codepen.io/artoo/pen/Zvomxr

aRtoo
@artoodeeto
Jan 15 2018 07:40
nevermind i got it now thanks
mitchell369
@mitchell369
Jan 15 2018 09:22
Hello, I would like to know more about the Boolean value in the solution for the falsy bouncer. What is implied when you just simply state "boolean"? Most docs I come across haven't really explained it adequately from what i've learned
Dan Couper
@DanCouper
Jan 15 2018 09:26
boolean refers to a logical boolean value, it's either true or false (maths/logic, not JS).
mitchell369
@mitchell369
Jan 15 2018 09:27
but why does it's use with filter only return true values?
Dan Couper
@DanCouper
Jan 15 2018 09:27
Also Boolean() is a JS function that converts whatever you pass to it to true or false
I think you're referring to that rather than the concept in general
mitchell369
@mitchell369
Jan 15 2018 09:27
@DanCouper I am more interested in it's properties as a value
Dan Couper
@DanCouper
Jan 15 2018 09:28
Not quite sure what you mean
boolean is not a value
mitchell369
@mitchell369
Jan 15 2018 09:28
return arr.filter(Boolean);
Dan Couper
@DanCouper
Jan 15 2018 09:28
That's the function
It's not a value
mitchell369
@mitchell369
Jan 15 2018 09:28
why will it return only truthy values in a given array
Dan Couper
@DanCouper
Jan 15 2018 09:28
It's the same as writing
arr.filter(value => Boolean(value))
It is running the Boolean function for each value in the array
mitchell369
@mitchell369
Jan 15 2018 09:30
hmmm interesting that it is assumed rather than requiring definition
Dan Couper
@DanCouper
Jan 15 2018 09:31
Not assumed, it's called beta or zeta reduction, I forget which
Can be a bit confusing
mitchell369
@mitchell369
Jan 15 2018 09:31
but why don't you need to specify that filter should only retain truthy values?
what operator returns only falsy values?
Dan Couper
@DanCouper
Jan 15 2018 09:33
The filter function takes an array, and runs a given function on every element in the array. It returns a new array for every element the given function returns true
So like
[1,2,3].filter(value => value > 1) - this returns [2,3] because those are the values greater than one - the function given says return true if the value is greater than 1
And re Boolean
mitchell369
@mitchell369
Jan 15 2018 09:36
but merely passing Boolean through the function is sufficient to produce this interpretation... no comparison operators necessary...
Dan Couper
@DanCouper
Jan 15 2018 09:37
Boolean(0) returns false, Boolean(1) returns true, Boolean(null) returns false, Boolean("hello") returns true
The Boolean function coerces anything you give it to true or false according to the rules of JS
mitchell369
@mitchell369
Jan 15 2018 09:40
Yah I tihnk I get it, it already has a defined set of rules to produce true and false, filter only produces values that are assigned as true
true is already pre-defined in the function
thank you @DanCouper
CamperBot
@camperbot
Jan 15 2018 09:40
mitchell369 sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 863 | @dancouper |http://www.freecodecamp.org/dancouper
Dan Couper
@DanCouper
Jan 15 2018 09:43
There is another aspect to this - the Boolean function is used by JS under the hood for filter anyway - anything you give to filter, JS will try to convert to true or false to make sure that it doesn't blow up, that it always returns something. So you can do
`arr.fipt
So
arr.filter(value => value)
i.e. a function that just returns the value you give it
Because
Filter already takes that value and converts it to true or false
mitchell369
@mitchell369
Jan 15 2018 09:54
are you saying arr.fipt == arr.filter (value => value) ?
Markus Kiili
@Masd925
Jan 15 2018 10:03
@mitchell369 arr.filter (value => value) filters in truthy array elements, the same as arr.filter (Boolean).
Dan Couper
@DanCouper
Jan 15 2018 10:28
arr.fipt is me mistyping @mitchell369
mitchell369
@mitchell369
Jan 15 2018 12:43
Good afternoon goyim. Can any of you good goys help me work of why my if statement is n't evaluating non-alpha characters in my code?

function rot13(str) { // LBH QVQ VG!
var numStr = str.split("").map(function (char) {

return String.fromCharCode(64 < char < 72 ? char.charCodeAt() % 26 + 65 : char);
});
return numStr;
}

I have passed through values like ' and it wants to assign them the samevalue as "A"
Stephen James
@sjames1958gm
Jan 15 2018 12:46
@mitchell369 64 < char < 72 this is not valid syntax
@mitchell369 Well it is not testing what you want.
What you end up with is essentially (64 < char) < 72 which is testing true/false < 72
mitchell369
@mitchell369
Jan 15 2018 12:48
@sjames1958gm ok, I can understand that as someone who wasn't completely hopelessin math
Unwana Essien
@afixoftrix
Jan 15 2018 12:48

hello there, I have a web pack/ babel problem
my loaders:

module: {
        loaders: [
            {
                test: /\.js$/,
                loader: 'babel-loader',
                query: {
                    presets: ['es2015']
                }
            }
        ]
    },

Here is the error I am getting:

^CMacBook-Pro:redux-learn Owner$ npm run-script watch

> redux-learn@1.0.0 watch /Users/Owner/Dev/Test Dump/redux-learn
> webpack --watch


Webpack is watching the files…

(node:2086) DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/issues/56
parseQuery() will be replaced with getOptions() in the next major version of loader-utils.
Hash: e1004b9f03431443d6e6
Version: webpack 3.10.0
Time: 1232ms
             Asset     Size  Chunks             Chunk Names
    main.bundle.js   3.4 kB       0  [emitted]  main
main.bundle.js.map  2.46 kB       0  [emitted]  main
   [0] ./main.js 890 bytes {0} [built] [failed] [1 error]

ERROR in ./main.js
Module build failed: SyntaxError: Unexpected token (20:21)

  18 |     switch (action.type) {
  19 |         case "CHANGE_NAME": {
> 20 |             state = {...state, name: action.payload};
     |                      ^
  21 |             break;
  22 |         }
  23 |         case "CHANGE_AGE": {
Stephen James
@sjames1958gm
Jan 15 2018 12:49
@mitchell369 You need 64 < char && char < 72 to have two numeric comparisons
mitchell369
@mitchell369
Jan 15 2018 12:50
@sjames1958gm so can I use a colon after the first evalution then see if it is <|> ?
ok, I don't havemuch experience with && but I will give that a go
Stephen James
@sjames1958gm
Jan 15 2018 12:50
@mitchell369 Just read && as AND
Unwana Essien
@afixoftrix
Jan 15 2018 12:50
I don't understand why it doesn’t understand spread operator.
mitchell369
@mitchell369
Jan 15 2018 12:52
@sjames1958gm That completely destroy the output lol
Stephen James
@sjames1958gm
Jan 15 2018 12:52
@mitchell369 char.charCodeAt() % 26 + 65 what is this trying to do?
Markus Kiili
@Masd925
Jan 15 2018 12:54
@sjames1958gm Spread operator is ES6 (ES2015).
mitchell369
@mitchell369
Jan 15 2018 12:55
@sjames1958gm Its evaluating the remainder when I pass it through 26 character alphabet, I found that is the most effective method to produce the A => N conversion and Z => M or w/e it is. Adding the 65 get's you back to the Ascii recognized coding for A-Z
Unwana Essien
@afixoftrix
Jan 15 2018 12:57
@mitchell369 Ok I just added babel ‘stage-3’ presets and it worked.
Stephen James
@sjames1958gm
Jan 15 2018 12:59
@Masd925 Odd, it appears that for some reason babel doesn't work for objects like above with just es2015 preset
Markus Kiili
@Masd925
Jan 15 2018 13:00
@sjames1958gm Compatibility of spread also differs depending on where/how it is used.
Stephen James
@sjames1958gm
Jan 15 2018 13:01
@mitchell369 Why is the second number 72? and not 91 (one more than Z
mitchell369
@mitchell369
Jan 15 2018 13:02
@sjames1958gm right on, good start... should be 92
Stephen James
@sjames1958gm
Jan 15 2018 13:03
@mitchell369 BTW, your 64 < char && char < 72 is comparing the string value char not the char code of char
mitchell369
@mitchell369
Jan 15 2018 13:06
@sjames1958gm That's a good lead, basically what I see it doing is changing all values that fall below that range into 65 and providing me with the output
Stephen James
@sjames1958gm
Jan 15 2018 13:06
@mitchell369 You need to make sure that the types in your variables match the types you are comparing
mitchell369
@mitchell369
Jan 15 2018 13:12
@sjames1958gm specifying the the limits within the charCodeAt(), seems to return hex values...
Stephen James
@sjames1958gm
Jan 15 2018 13:21
@mitchell369 Your algorithm is close. just that the comparison should be with charCode not char
var c = char.charCodeAt();
return String.fromCharCode(64 < c && c < 91 ? c % 26 + 65 : c);
Ahmad Abdolsaheb
@ahmadabdolsaheb
Jan 15 2018 14:11

hey everyone, I am trying to use filter, however, i want it to some times not filter anything. this is currently what i have

cards.filter(card=> card.type == "awards")

i have a variety of cards and sometimes i want filter to include all of the cards. how can I do that?

Ken Haduch
@khaduch
Jan 15 2018 14:13

@ahmadabdolsaheb - without knowing all that you're doing, how about not calling the .filter when you don't want to actually filter, or if you make a "control" variable like this:

let doAll = true;
cards = cards.filter(card=> card.type == "awards" || doAll );

So that you can set doAll to the value you want (based on some condition) and then it would always pass the test? That's at least one take at it... You have to catch the return from the .filter, so I just threw that in there...

Ahmad Abdolsaheb
@ahmadabdolsaheb
Jan 15 2018 14:20
@khaduch so cards.filter(card=> card.type == true ); does not seem to return all items.
i tried it in js fiddle
array = [1,2,3,5]; console.log(array.filter(num => num == true)); only returns one
Markus Kiili
@Masd925
Jan 15 2018 14:24
@ahmadabdolsaheb What are you trying to do? Why use abstract equality == (which nobody remember how it works really).
Ahmad Abdolsaheb
@ahmadabdolsaheb
Jan 15 2018 14:25
@Masd925 i have cards with different types. i wanna show a specific card type when a relevant button is pressed. but, sometime, i wanna show all cards.
i am trying to use filter not to filter :)
cards.filter(card=> card.type == "awards")
what should I use instead of "awards and includes everything
or
cards.filter(card=> card.type === "awards")
Markus Kiili
@Masd925
Jan 15 2018 14:28
@ahmadabdolsaheb There is no value that would be equal to all strings. cards.filter(card => true) would keep all elements.
cards.filter(card => card.type) would also keep all cards provided that types are non-empty strings.
@ahmadabdolsaheb I think that changing the logic as @khaduch said is best.
Ahmad Abdolsaheb
@ahmadabdolsaheb
Jan 15 2018 14:33
@Masd925 @khaduch i think i will change logic since making a control variable didn't work. thanks
CamperBot
@camperbot
Jan 15 2018 14:33
ahmadabdolsaheb sends brownie points to @masd925 and @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3677 | @khaduch |http://www.freecodecamp.org/khaduch
:star2: 4653 | @masd925 |http://www.freecodecamp.org/masd925
Ken Haduch
@khaduch
Jan 15 2018 14:48
:point_up: January 15, 2018 9:20 AM @ahmadabdolsaheb - you need to do something like what I posted in my comment above yours - cards = cards.filter(card=> card.type == "awards" || doAll ); - the variable doAll would be set to true or false (or something that evaluated to true or false) and if it did not match the first conditional test, then if doAll evaluated to true, it would add the card to the output array. It is the || "or" condition that makes it work. It is a common way to affect conditional tests. So it will work, but it might not always be the best way to do things, for example, if you have a 1000 element array that you don't need to filter, then maybe it is not too efficient to do this (just thinking of performance).
Jason Luboff
@JLuboff
Jan 15 2018 16:07
:wave:
Gersho
@Gersho
Jan 15 2018 16:08
:wave:
Jason Luboff
@JLuboff
Jan 15 2018 16:08
What up
Markus Kiili
@Masd925
Jan 15 2018 16:11
Yo
Jason Luboff
@JLuboff
Jan 15 2018 16:12
@Masd925 Yo'
Kaz Baig
@kbaig
Jan 15 2018 16:13
:wave:
Jason Luboff
@JLuboff
Jan 15 2018 16:15
Whats good?
Kaz Baig
@kbaig
Jan 15 2018 16:18
TFW you were sick last week so you didn't get much done at work, but now you're even more sick and need to start working harder to catch up :(
Jason Luboff
@JLuboff
Jan 15 2018 16:20
Flu?
Markus Kiili
@Masd925
Jan 15 2018 16:21
@JLuboff I finally did a portfolio page.
Jason Luboff
@JLuboff
Jan 15 2018 16:21
@Masd925 Impressive!
Kaz Baig
@kbaig
Jan 15 2018 16:21
@JLuboff sinus infection into bronchitis about 4 weeks ago that almost ended but now I'm coughing hard again and throat is swollen :(
Jason Luboff
@JLuboff
Jan 15 2018 16:22
@kbaig Shitty. Did you get antibiotics for it?
Kaz Baig
@kbaig
Jan 15 2018 16:23
@JLuboff Doc gave me some in case it's bacterial pneumonia, which they were seeing some cases of. But no, nothing to directly treat it as they thought it was probably viral
Markus Kiili
@Masd925
Jan 15 2018 16:23
@JLuboff I have to do a better one at some point but at least I can put some projects there http://www.cleanprogramming.com Lacks my picture too at the moment.
Kaz Baig
@kbaig
Jan 15 2018 16:24
@Masd925 what did you use for the particles?
Markus Kiili
@Masd925
Jan 15 2018 16:24
@kbaig JS
Kaz Baig
@kbaig
Jan 15 2018 16:24
No library?
Markus Kiili
@Masd925
Jan 15 2018 16:25
I made a physics engine earlier for making some JS games and that uses it.
Jason Luboff
@JLuboff
Jan 15 2018 16:25
@kbaig Lame. Hope you get well soon
Kaz Baig
@kbaig
Jan 15 2018 16:25
@Masd925 oh cool. Maybe you'd enjoy looking at the source code for ParticleJS?
thanks bud
@JLuboff
Jason Luboff
@JLuboff
Jan 15 2018 16:26
@Masd925 Master's degree in Theoretical and Mathematical Physics with a focus on particle physics eh?
Markus Kiili
@Masd925
Jan 15 2018 16:26
@JLuboff That was 20 years ago. Don't remember any of that ;)
Kaz Baig
@kbaig
Jan 15 2018 16:27
unlucky
Jason Luboff
@JLuboff
Jan 15 2018 16:27
@Masd925 And then another degree just a few years ago. Mean while, I'm over here with just an Associates degree haha
Kaz Baig
@kbaig
Jan 15 2018 16:28
Can someone pay for the 2 masters I'd like to do but can't imagine paying for? thx
Markus Kiili
@Masd925
Jan 15 2018 16:29
@kbaig Yes, some library would do it too (and better) but maybe doing it by hand has some value too.
Kaz Baig
@kbaig
Jan 15 2018 16:30
@Masd925 For sure. I just mean that you have the background to maybe more easily comprehend what's going on in ParticleJS's source
For learning purposes
Markus Kiili
@Masd925
Jan 15 2018 16:32
@kbaig Yeah. Must be something similar going on there too.
Gersho
@Gersho
Jan 15 2018 16:34
@Masd925 in the "scenery" section, if you go in one direction multiple time, when you hit the end, it scrolls back to the start rather than looping
Markus Kiili
@Masd925
Jan 15 2018 16:37
@Gersho Yes. That is the default way in that fullpage.js library. Not sure which way is the best.
Gersho
@Gersho
Jan 15 2018 16:38
well it's not really an issue, but it felt weird so it taught i'd mention it
Markus Kiili
@Masd925
Jan 15 2018 16:38
@Gersho ok. Thanks. I will compare and maybe change it later.
CamperBot
@camperbot
Jan 15 2018 16:38
masd925 sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 582 | @gersho |http://www.freecodecamp.org/gersho
Onome Sotu
@onomesotu
Jan 15 2018 18:44
Can anyone recommend the best way to learn react?
SOmething that will explain using webpack
I do not understand what webpack does and why you use it if you are using gulp too
Kaz Baig
@kbaig
Jan 15 2018 18:47
you prob want to decouple the learning there
ie learn react separately from webpack
the official tutorial for React is not a bad place to start
Khalid Powell
@KhalidPowell
Jan 15 2018 18:52
I have a question about the "Diff Two Arrays" challenge. Do we absolutely have to use the filter() function? Can't we get by with the indexOf() function?
Kaz Baig
@kbaig
Jan 15 2018 18:52
@KhalidPowell if you're using for loops sure
Jason Luboff
@JLuboff
Jan 15 2018 18:56
@KhalidPowell You never have to use the suggested methods, they are merely suggestions
Khalid Powell
@KhalidPowell
Jan 15 2018 18:57
yeah I should be able to check if element[i].indexOf(whatever) == -1 and then concat it to the end of the array I plan on returning right?
Onome Sotu
@onomesotu
Jan 15 2018 19:19
@kbaig thanks
CamperBot
@camperbot
Jan 15 2018 19:19
onomesotu sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 525 | @kbaig |http://www.freecodecamp.org/kbaig
Onome Sotu
@onomesotu
Jan 15 2018 19:20
@KhalidPowell you could just push straight to the array you plan to return
Khalid Powell
@KhalidPowell
Jan 15 2018 19:26
@onomesotu thanks that was the issue. I must have been using concat() wrong
CamperBot
@camperbot
Jan 15 2018 19:26
khalidpowell sends brownie points to @onomesotu :sparkles: :thumbsup: :sparkles:
:cookie: 298 | @onomesotu |http://www.freecodecamp.org/onomesotu
Onome Sotu
@onomesotu
Jan 15 2018 19:31
@KhalidPowell my pleasure
JBallin
@JBallin
Jan 15 2018 19:53
Eloquent JavaScript asks: you can either reverse an array in place or by creating a new reversed array. which is useful in more situations? which is more efficient?
Jason Luboff
@JLuboff
Jan 15 2018 19:57
@JBallin They both accomplish the same thing. Regardless of the method, you're modifying the original array.
alpox
@alpox
Jan 15 2018 19:57
There is no modification of the original array if you create a new reversed array out of the original array, unless i misunderstood the question :D
Jason Luboff
@JLuboff
Jan 15 2018 19:58
@alpox maybe I'm misunderstood the question to then...but
let arr = [1,2,3];
let arr2 = arr.reverse();
console.log(arr, arr2); // result: [3,2,1], [3,2,1]
JBallin
@JBallin
Jan 15 2018 19:59
@JLuboff @alpox is right. i'm talking about implementing a reverse method that creates a new array.
Jason Luboff
@JLuboff
Jan 15 2018 19:59
Ah.. so you mean creating an empty array then pushing the values to it? Is that correct?
alpox
@alpox
Jan 15 2018 20:00
I guess thats what he talks about, yes.
JBallin
@JBallin
Jan 15 2018 20:01
@JLuboff
function reverseArray(array) {
  reversed = [];
  for (var i = array.length - 1; i > -1; i--) {
    reversed.push(array[i]);
  }
  return reversed;
}
alpox
@alpox
Jan 15 2018 20:01
^
For me the answer to this question is fully dependant on the usecase
alpox
@alpox
Jan 15 2018 20:03
I mean if you need to keep the original array, the latter method is surely better suited.
If you have big arrays and have to care about memory space, the first m ethod is sure better.
I also believe that the first method is faster because of the dynamic allocation of the new array where you push elements into.
Except you change the algorithm slightly
function reverseArray(array) {
  reversed = new Array(array.length);
  for (var i = array.length - 1; i > -1; i--) {
    reversed[i] = array[i];
  }
  return reversed;
}
Should be faster in theory
JBallin
@JBallin
Jan 15 2018 20:05
@alpox i agree, that's why im confused. the author seems to be implying that there are correct answers to these questions though.
i guess i'll accept that it's a bit more complicated than he's making it out to be
Jason Luboff
@JLuboff
Jan 15 2018 20:06
I personally didn't care for Eloquent JS solely for the authors writing style
alpox
@alpox
Jan 15 2018 20:08
@JBallin In the book he just says that reversing the array in-place is harder. That doesn't say anything about efficiency and its also not REALLY hard. He didn't even answer his own questions in the hints.
For me this looks just like not a good resource
But i know people are praising Eloquent JS. I didn't read it, so i cannot tell - but from this source, i'd keep distance ^^
JBallin
@JBallin
Jan 15 2018 20:09
@alpox thanks for chiming in!
CamperBot
@camperbot
Jan 15 2018 20:09
jballin sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1520 | @alpox |http://www.freecodecamp.org/alpox
JBallin
@JBallin
Jan 15 2018 20:09
@JLuboff I've actually been enjoying it. do you recommend a different beginner JS book? I wanted to read the YDKJS series next.
alpox
@alpox
Jan 15 2018 20:10
YDKJS looked nice to me
From what i've seen
Jason Luboff
@JLuboff
Jan 15 2018 20:10
I've only gotten through the first YDKJS book, but I liked it a lot more than EJS
JBallin
@JBallin
Jan 15 2018 20:11
cool cool @JLuboff thanks for the feedback!
CamperBot
@camperbot
Jan 15 2018 20:11
jballin sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2297 | @jluboff |http://www.freecodecamp.org/jluboff
Diego Mayer
@Chrono79
Jan 15 2018 20:47
@JLuboff
let arr = [1,2,3];
let arr2 = arr.slice().reverse();
console.log(arr, arr2); // result: [1,2,3], [3,2,1]
Jason Luboff
@JLuboff
Jan 15 2018 20:47
@Chrono79 Touche touche
Diego Mayer
@Chrono79
Jan 15 2018 20:48
Don't know if faster or more efficient, less writing for sure and not mutating the original array
Christopher McCormack
@cmccormack
Jan 15 2018 20:49
@Chrono79 use some destructuring!
let arr2 = [...arr].reverse()
This is how all the cool kids are doing it now
Diego Mayer
@Chrono79
Jan 15 2018 20:49
@cmccormack :+1:
Jason Luboff
@JLuboff
Jan 15 2018 20:49
La-de-da
Christopher McCormack
@cmccormack
Jan 15 2018 20:50
it does make it a lot easier when building new arrays from old arrays
Kaz Baig
@kbaig
Jan 15 2018 20:52
my favorite use of destructuring and spread:
const [a, b, ...c] = [0, 1, 2, 3, 4];

console.log(a); // 0
console.log(b); // 1
console.log(c); // [2, 3, 4]
Diego Mayer
@Chrono79
Jan 15 2018 20:53
I'm going crazy with a css problem about different browsers breaking words wherever they want, is there a way to prevent it at all?
Christopher McCormack
@cmccormack
Jan 15 2018 20:53
yeah
Diego Mayer
@Chrono79
Jan 15 2018 20:54
I've looked over word-wrap, word-break, and hyphen, no luck with those (at least for now)
Christopher McCormack
@cmccormack
Jan 15 2018 20:54
@Chrono79 are you seeing long words broken over lines?
Kaz Baig
@kbaig
Jan 15 2018 20:54
@cmccormack isn't that spread, not destructuring? Maybe I have my terms mixed up
Diego Mayer
@Chrono79
Jan 15 2018 20:55
I know it's off topic in javascript channel, so sorry
@cmccormack no, I see text broken in syllabes when there is no need and it should continue in the next line
@kbaig it seems he's using both there (I could be wrong)
Christopher McCormack
@cmccormack
Jan 15 2018 20:56
@kbaig yeah probably, I confuse the terms often
it says rest pattern there
Christopher McCormack
@cmccormack
Jan 15 2018 21:01
spread 'expands' an array into its elements, while rest collects multiple elements and 'condenses' them into a single element.
Kaz Baig
@kbaig
Jan 15 2018 21:02
aha
so I used rest and destructuring, while you used spread
rest is when you're collecting, spread is when you're...spreading
Christopher McCormack
@cmccormack
Jan 15 2018 21:03
yeah :) I guess it makes sense
and I don't think it's all mutually exclusive, you can use rest within destructuring, which I often do
like in react you can do something like
const NavItem = ({ color, id, ...props}) => { ...
that's destructuring the props passed to the functional component as well as using rest after isolating a few properties from the props argument
Kaz Baig
@kbaig
Jan 15 2018 21:07
mhmm
Christopher McCormack
@cmccormack
Jan 15 2018 21:08
@Chrono79 maybe try overflow: hidden;? not sure if that's what you're looking for
Fixed width div I assume?
or overflow-x: scroll;
Jason Luboff
@JLuboff
Jan 15 2018 21:15
meanwhile I'm over here like int[] arr = new int[5]
Kaz Baig
@kbaig
Jan 15 2018 21:16
boooooooooo
we don't like that here
Jason Luboff
@JLuboff
Jan 15 2018 21:17
:joy:
Diego Mayer
@Chrono79
Jan 15 2018 21:17
Then I won't mention exploring Swift and Crystal earlier today
Kaz Baig
@kbaig
Jan 15 2018 21:18
Swift
Diego Mayer
@Chrono79
Jan 15 2018 21:18
D'oh!
Kaz Baig
@kbaig
Jan 15 2018 21:18
ugh
Jason Luboff
@JLuboff
Jan 15 2018 21:18
I needed to create a multi-data type array and I ws all like "Damn..I can't use an array!" so I had to create a List.. but then I didn't need it lol
Kaz Baig
@kbaig
Jan 15 2018 21:18
I had to write one snippet of Swift calling a webhook at work and hated it
But nowhere near as much as doing the same for Java, which took 3x as much code
Idowu Wasiu
@Hoxtygen
Jan 15 2018 21:43
hello guys, I'm stuck with the wikipedia viewer challenge
js code doesnt seem to work
getting an empty array returned, and the value of the search box isnt getting to the api.............. any help will be appreciated
Jason Luboff
@JLuboff
Jan 15 2018 21:46
@Hoxtygen var url = 'https://en.wikipedia.org/w/api.php?action=opensearch&search=json&redirects=return&origin=*&search= + searchInput'; You need to fix your use of quotes here
Should be var url = 'https://en.wikipedia.org/w/api.php?action=opensearch&search=json&redirects=return&origin=*&search=' + searchInput;
Christopher McCormack
@cmccormack
Jan 15 2018 21:48
@JLuboff :thumbsup: so fast! :speedboat:
Jason Luboff
@JLuboff
Jan 15 2018 21:49
I'm a speedboat eh?
Idowu Wasiu
@Hoxtygen
Jan 15 2018 21:49
@JLuboff Thank you
CamperBot
@camperbot
Jan 15 2018 21:49
hoxtygen sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2298 | @jluboff |http://www.freecodecamp.org/jluboff
Christopher McCormack
@cmccormack
Jan 15 2018 21:50
@JLuboff yes you are
Jason Luboff
@JLuboff
Jan 15 2018 21:50
@Hoxtygen :+1:
Idowu Wasiu
@Hoxtygen
Jan 15 2018 21:50
@JLuboff works now, getting something in the console.............. wish I could give another 999 brownies
Jason Luboff
@JLuboff
Jan 15 2018 21:51
@cmccormack But I get sea sick :barf: (I guess there's no barf emoji on here)
Idowu Wasiu
@Hoxtygen
Jan 15 2018 21:51
@JLuboff how on earth did you spot that fast?
Jason Luboff
@JLuboff
Jan 15 2018 21:52
@Hoxtygen I consoled the search inbox variable first, and saw it was getting the correct input, so then I went to check the URL variable and saw that
Idowu Wasiu
@Hoxtygen
Jan 15 2018 21:54
@JLuboff I did console the searchInput first too, got baffled when empty arrays keep popping up as the final output..... need to get a quick fix on the use of quotes.
@JLuboff someone bailed me out too on the last project, got screwed by quotes
Jason Luboff
@JLuboff
Jan 15 2018 22:00
@Hoxtygen You may want to look into using template strings instead of regular strings. It's easy to do. Instead of using ' or " you use `` and then for your variables you wrap them in${ }` so you would have
var url = `https://en.wikipedia.org/w/api.php?action=opensearch&search=json&redirects=return&origin=*&search=${searchInput}`;
Damn it. Won't let me edit anymore lol
Idowu Wasiu
@Hoxtygen
Jan 15 2018 22:03
@JLuboff oh! saw something similar when shoving PHP into my head just yesterday.... damn it, how could i have forgotten so fast.
Jason Luboff
@JLuboff
Jan 15 2018 22:06
It's all I use.
Henry
@GitHub-Henry
Jan 15 2018 22:24
anyone tried vs2017 with js and node apps?