These are chat archives for FreeCodeCamp/Help

28th
Mar 2018
Ken Haduch
@khaduch
Mar 28 2018 00:00
I seem to have forgotten how .reduce() works... :(
Kyle Holm
@thekholm80
Mar 28 2018 00:02
returns a single value, iterates over an array with Array.reduce((accumulator, currentValue, index, copyOfArray) => {}, initialvalue, thisValue)
i'm sure i've initialized the accumulator as an empty array before and used methods like push() and whatnot, but it's really not liking the spread operator
Ken Haduch
@khaduch
Mar 28 2018 00:07
@thekholm80 - ya, but I thought that I used to have some things working where I started with an empty array as the initial value and was able to .push() onto it? It doesn't seem to work anymore? Unless I have something messed up somewhere.... Oh, Okay - I was just messing up slightly. I think this works, with your example:
const oldArray = [1, 2, 0, 3];
const newArray = oldArray.reduce(function (acc, el, idx, inArray) {
  console.log(acc, inArray, el);
  if (el > 0) {
    acc.push(el);
    return acc;
  } 
  return acc;
}, []);
console.log(newArray); // [1, 2, undefined, 3]
I didn't try the spread operator... and fell back to old-style functions. Just a little thrashing around in my confusion... :)
Kyle Holm
@thekholm80
Mar 28 2018 00:08
:)
Ken Haduch
@khaduch
Mar 28 2018 00:11
but it works. So now about the spread operator - is it necessary here?
I think that you just need a return a; in your example if you don't have the b>0
Kyle Holm
@thekholm80
Mar 28 2018 00:12
if you can't do it with style, why bother?
Ken Haduch
@khaduch
Mar 28 2018 00:13
const oldArray = [1, 2, 0, 3];
const newArray = oldArray.reduce((acc, el) => {
  if (el > 0) {
    return [...acc,el];
  } 
  return acc;
}, []);
console.log(newArray); // [1, 2, undefined, 3]
That seems to work
Kyle Holm
@thekholm80
Mar 28 2018 00:14
ah, yeah
that makes sense
Ken Haduch
@khaduch
Mar 28 2018 00:14
you always have to return something...
Kyle Holm
@thekholm80
Mar 28 2018 00:14
so i'm not very bright ... we all knew that
Ken Haduch
@khaduch
Mar 28 2018 00:14
and I'm very forgetful. I'm constantly getting reminded...
Kyle Holm
@thekholm80
Mar 28 2018 00:15
@khaduch thanks
CamperBot
@camperbot
Mar 28 2018 00:15
thekholm80 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3828 | @khaduch |http://www.freecodecamp.org/khaduch
Kyle Holm
@thekholm80
Mar 28 2018 00:15
yay it worked that time
Ken Haduch
@khaduch
Mar 28 2018 00:15
:) persistence sometimes pays off! :)
and you're welcome. And thanks for shaking the brain cells, @thekholm80
CamperBot
@camperbot
Mar 28 2018 00:15
khaduch sends brownie points to @thekholm80 :sparkles: :thumbsup: :sparkles:
:star2: 1749 | @thekholm80 |http://www.freecodecamp.org/thekholm80
Kyle Holm
@thekholm80
Mar 28 2018 00:16
so lemme try that with the original code
Ken Haduch
@khaduch
Mar 28 2018 00:16
okay I'm going to step away for a bit, but will be checking in on the computer in a little while.
Kyle Holm
@thekholm80
Mar 28 2018 00:18
@khaduch worked like a charm
const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];
const squareList = (arr) => {
  "use strict";
  // change code below this line
  const squaredIntegers = arr.reduce((a, b) => {
    if (Number.isInteger(b) && b > 0) {
      return [...a, Math.pow(b, 2)];
    }
    return a;
  }, []);
  return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers); // [16, 1764, 36]
Ken Haduch
@khaduch
Mar 28 2018 00:19
:+1: :zap:
Kyle Holm
@thekholm80
Mar 28 2018 00:19
now to make it pretty const squaredIntegers = arr.reduce((a, b) => (Number.isInteger(b) && b > 0) ? [...a, Math.pow(b, 2)] : a, []);
Ken Haduch
@khaduch
Mar 28 2018 00:21
@thekholm80 - I just did that with the example:
const oldArray = [1, 2, 0, 3];
const newArray = oldArray.reduce((acc, el) => (el > 0) ? [...acc,el] : acc, []);
console.log(newArray); // [1, 2, undefined, 3]
Kyle Holm
@thekholm80
Mar 28 2018 00:21
lol
ternaries are my favorite
and tuples, but javascript isn't cool enough for tuples
shilefengwodeairen
@shilefengwodeairen
Mar 28 2018 00:26
<p>Click here for <a href="#"><img src="/images/relaxing-cat.jpg">cat photos</a>.</p>
help,
where is wrong
你可以通过把某元素嵌套进a元素使其变成一个链接。
把你的图片嵌套进a元素。举例如下:
<a href="#"><img src="/images/relaxing-cat.jpg"></a>
任务:把你的小猫图片插入到一个新的锚点元素中,并把锚点元素的href属性设置为#。
一旦完成,把你的光标悬停在你的图片上。你的光标此时应该由光标指针变成手形指针。图片现在是一个链接了。
Kyle Holm
@thekholm80
Mar 28 2018 00:27
Kyle Holm
@thekholm80
Mar 28 2018 00:37
@khaduch is there a better way in python?
realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34]

def squareList (arr):
  squaredIntegers = []
  for el in arr:
    if isinstance(el, int) and el > 0:
      squaredIntegers.append(el**2)
  return squaredIntegers

print(squareList(realNumberArray)) // [16, 1764, 36]
Ken Haduch
@khaduch
Mar 28 2018 00:37
@thekholm80 - ohhh, I don't know python very well. Just trying to learn that! :(
Kyle Holm
@thekholm80
Mar 28 2018 00:38
@khaduch oh crap, i thought you were a python pro
i must have you confused with someone
oh i'm thinking @JohnnyBizzel
must be the mustaches getting me confused
Johnny
@JohnnyBizzel
Mar 28 2018 00:40
@thekholm80 I like watching Monty Python, does that count :joy:
Kyle Holm
@thekholm80
Mar 28 2018 00:40
@JohnnyBizzel haha
Ken Haduch
@khaduch
Mar 28 2018 00:41
Hey, I loved Monty Python! And now for something completely different...
Johnny
@JohnnyBizzel
Mar 28 2018 00:41
:P
Ken Haduch
@khaduch
Mar 28 2018 00:43
I'll bet there's a one-liner in Python for that... :)
Kyle Holm
@thekholm80
Mar 28 2018 00:44
oh i bet you're right
i'm a python noob though
Ken Haduch
@khaduch
Mar 28 2018 00:47
I'm a python (noob - 1)
Kyle Holm
@thekholm80
Mar 28 2018 00:47
doing the easy katas on codewars has really helped learning python
Ken Haduch
@khaduch
Mar 28 2018 00:54
@thekholm80 - hey, how about a list comprehension?
Kyle Holm
@thekholm80
Mar 28 2018 00:54
i'm not sure what you mean
oh, this
you know, i think that's the bunny
realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34]

def squareList(arr):
 return [el**2 for el in arr if isinstance(el, int) and el > 0]
it worked, awesome @khaduch
Ken Haduch
@khaduch
Mar 28 2018 00:59
@thekholm80 - I just wrote the same thing!
def sqlist(arr):
     return [ elem**2 for elem in arr if isinstance(elem, int) and elem > 0 ]
print(sqlist(realNumberArray))
Kyle Holm
@thekholm80
Mar 28 2018 00:59
lol great minds, what?
Ken Haduch
@khaduch
Mar 28 2018 01:00
that "comprehension" thing is something that has been covered in some of the lessons that I've gone through so far. :)
Kyle Holm
@thekholm80
Mar 28 2018 01:01
i've used it before, i just didn't know what it was called. i still haven't done enough python to remember all the cool things so i always fall back to explicit code
Johnny
@JohnnyBizzel
Mar 28 2018 01:23

@thekholm80 I was looking at that algo for a while, trying to use yield and generator expressions:

realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34]


def square_list(arr):
    ints = (
        num
        for num in realNumberArray
        if isinstance(num, int)  # test (if int)
    )

    for el in ints:
        if el > 0:
            yield el**2


print(list(square_list(realNumberArray)))  # [16, 1764, 36]

I think it works :/
I believe the benefit is it doesn't use tons of memory if it's a big collection you are searching.

Anyway, bed time :zzz:
Kyle Holm
@thekholm80
Mar 28 2018 01:27
@JohnnyBizzel g'night Johnny
Infinitymann
@Infinitymann
Mar 28 2018 01:50
hello, I built a javascript in p5.js which creates HTML elements on a web page for each item in a JSON file, but it won't scroll. Any ideas?
Ken Haduch
@khaduch
Mar 28 2018 02:42
@Infinitymann - hello - that's not a lot of information to go on - do you have a URL for your project that can be accessed? One thing that I could say to check on, perhaps, is the setting of the overflow CSS properties - overflow-x, overflow-y, you can look at documentation of those https://developer.mozilla.org/en-US/docs/Web/CSS/overflow and see? Not sure what to think about it otherwise?
Kyle Holm
@thekholm80
Mar 28 2018 02:43
@khaduch some fun for you
Ken Haduch
@khaduch
Mar 28 2018 02:54
@thekholm80 :confused:
Kyle Holm
@thekholm80
Mar 28 2018 02:55
i've been working on that for a while now lol
^(?(?=\d\.02)[0-2]|(?(?=\d\.(0[4|6|9]|11))[0-3](?(?<=3)0|\d)|(?(?=\d\.(0[1|3|5|7|8]|10|12))[0-3](?<=3) the story so far, nearly got the days done
Ken Haduch
@khaduch
Mar 28 2018 02:57
that's a crazy one! Especially the leapyear part and days of the month... yikes! :exclamation:
Kyle Holm
@thekholm80
Mar 28 2018 02:57

i liked this part:

maximum length of validator is 400 characters to avoid hardcoding. (shortest solution to date is 170 characters)

Ken Haduch
@khaduch
Mar 28 2018 02:59
@thekholm80 - yeah, that's nuts! I got it to pass 20, failed 5, errors 1 - so that's a solid majority! haha
Kyle Holm
@thekholm80
Mar 28 2018 02:59
lol
i'm thinking about going back to my original "screw learning regex" way of thinking
Ken Haduch
@khaduch
Mar 28 2018 03:00
well this is extreme...
Kyle Holm
@thekholm80
Mar 28 2018 03:00
this is an easy one, only ranked 5 kyu
@Manish-Giri says there are some that are ranked 1 kyu that are insane
Ken Haduch
@khaduch
Mar 28 2018 03:02
yeah, if this is a 5 and I think it's a little crazy, I would hate to see the 1's - ouch!
Kyle Holm
@thekholm80
Mar 28 2018 03:02
i don't dare look
Ken Haduch
@khaduch
Mar 28 2018 03:04
I have never done any kind of validation like that with a regex - it might be interesting to ponder it and try it for a new experience.
Kyle Holm
@thekholm80
Mar 28 2018 03:04
i'm trying to figure out how to do math right now, i don't want to try to hard-code every leap year
Ken Haduch
@khaduch
Mar 28 2018 03:08
what's the calculation for leap year? Years divisible by 4 and not divisible by 100?
Kyle Holm
@thekholm80
Mar 28 2018 03:08

from the wiki:

Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. For example, the years 1700, 1800, and 1900 are not leap years, but the year 2000 is

Ken Haduch
@khaduch
Mar 28 2018 03:09
oh, yeah
jamesgeth
@jamesgeth
Mar 28 2018 05:24
@jamesgeth
hi anyone is able to help out with this?
The block 4065960 on the Ethereum blockchain contains about _ transactions.
a) 4465789
b) 3465789
c) 1465789
d) 2465789
Darren
@DarrenfJ
Mar 28 2018 05:51
evening fCC
Ghost
@ghost~5a4a80acd73408ce4f859755
Mar 28 2018 05:53
@DarrenfJ :wave: morning :laughing:
Darren
@DarrenfJ
Mar 28 2018 06:02
@MuhammedKarim hi buddy! :wave: :D
Dirk W du Plooy
@dirkduplooy
Mar 28 2018 10:50
Hi all, does anybody know how to enable bootstrap 4.0 autocomplete / intellisense in Visual Studio Code?
Ghost
@ghost~5a4a80acd73408ce4f859755
Mar 28 2018 10:53
image.png
image.png
@dirkduplooy Check out these extensions maybe?
Dirk W du Plooy
@dirkduplooy
Mar 28 2018 11:01
@MuhammedKarim I did try those but it does not cover all the classes unfortunately :-) It is possible that Bootstrap 4.0 stable is not covered yet by extensions. Reason I ask there might be a beta somewhere out there
Ghost
@ghost~5a4a80acd73408ce4f859755
Mar 28 2018 11:09
@dirkduplooy sorry :( idk how i can help out then
Mandeep Sharma
@mandeephub
Mar 28 2018 11:26
Hey good afternoon to all
Ghost
@ghost~5a4a80acd73408ce4f859755
Mar 28 2018 11:27
@mandeephub goog afternoon to you
Mandeep Sharma
@mandeephub
Mar 28 2018 11:27
@MuhammedKarim where you are stucked
Ghost
@ghost~5a4a80acd73408ce4f859755
Mar 28 2018 11:27
@mandeephub I'm not stuck lol
Mandeep Sharma
@mandeephub
Mar 28 2018 11:28
hahaha this place is a magical place you get habitual
Loris Hanck
@Pouletcoq
Mar 28 2018 12:14
Hello, I need help to install learnyounode :worried: I always get an error ...
Claudio Restifo
@Marmiz
Mar 28 2018 12:25
@Pouletcoq which is?
Loris Hanck
@Pouletcoq
Mar 28 2018 13:01
module.js:471
    throw err;
    ^

Error: Cannot find module 'isarray'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/ubuntu/.nvm/versions/node/v6.11.2/lib/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js:32:15)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
but it works when i don't update npm
Kyle Holm
@thekholm80
Mar 28 2018 13:59
good morning, /help
May Kittens Devour Your Soul
@diomed
Mar 28 2018 14:00
'morning, Kyle
Kyle Holm
@thekholm80
Mar 28 2018 14:03
@diomed hey! welcome back
May Kittens Devour Your Soul
@diomed
Mar 28 2018 14:04
how is this JS waste/wonder land?
Kyle Holm
@thekholm80
Mar 28 2018 14:04
generally quiet, with random chance of code
May Kittens Devour Your Soul
@diomed
Mar 28 2018 14:05
nice forecats
are you known as Weatherman?
Kyle Holm
@thekholm80
Mar 28 2018 14:07
sometimes, but my friends call me "hey you"
Kyle Holm
@thekholm80
Mar 28 2018 15:00
@IsaakNazar do you understand ternary operators?
Nazar
@IsaakNazar
Mar 28 2018 15:02
@thekholm80 hi, I understand it, but cant figure out the logic, how to show the buttone
buttonOne && (this.state.input > 18) ? buttonTwo : buttonThree
Kyle Holm
@thekholm80
Mar 28 2018 15:02
i think you'll need to nest ternaries for this
Nazar
@IsaakNazar
Mar 28 2018 15:03
@thekholm80 ok, I'll try then
Kyle Holm
@thekholm80
Mar 28 2018 15:03
this.state.input
  ? this.state.input > 18
    ? buttonTwo
    : buttonThree
  : buttonOne
something like that
Claudio Restifo
@Marmiz
Mar 28 2018 15:05
@thekholm80 I'll fire you if you'd ever write something like that
Kyle Holm
@thekholm80
Mar 28 2018 15:05
@Marmiz you can't fire me, i quit
Claudio Restifo
@Marmiz
Mar 28 2018 15:05
You can't quit if I quit it first
Kyle Holm
@thekholm80
Mar 28 2018 15:06
i guess we both win?
lol
Claudio Restifo
@Marmiz
Mar 28 2018 15:06
now that we quit we have time for that trip to the bahamas we always delayed :cocktail: :palm_tree:
Nazar
@IsaakNazar
Mar 28 2018 15:07
@thekholm80 thx, the rest of code I'll try to fugure out
CamperBot
@camperbot
Mar 28 2018 15:07
isaaknazar sends brownie points to @thekholm80 :sparkles: :thumbsup: :sparkles:
:star2: 1750 | @thekholm80 |http://www.freecodecamp.org/thekholm80
Kyle Holm
@thekholm80
Mar 28 2018 15:07
@IsaakNazar i just read the instructions lol i guess you need 2 different pieces of state
Nazar
@IsaakNazar
Mar 28 2018 15:08
@thekholm80 this?
this.state = {
      input: '',
      userAge: ''
    }
Kyle Holm
@thekholm80
Mar 28 2018 15:09
This message was deleted
The CheckUserAge component's state should be initialized with a property of userAge and a property of input, both set to a value of an empty string.
i really don't know what they're actually looking for
Kyle Holm
@thekholm80
Mar 28 2018 15:14
it passed with this.state.userAge == '' ? buttonOne : this.state.userAge >= 18 ? buttonTwo : buttonThree but that's not using this.state.input anywhere
@Marmiz now you can fire me
Sweet Coding :)
@SweetCodingInc
Mar 28 2018 15:14
@thekholm80 That's correct
sorry I forgot
@thekholm80 Ser Kyle :wave:
Kyle Holm
@thekholm80
Mar 28 2018 15:15
it can't be correct, i have unused state
Sweet Coding :)
@SweetCodingInc
Mar 28 2018 15:15
@thekholm80 challenge link?
Claudio Restifo
@Marmiz
Mar 28 2018 15:17
is FCC really promoting the usage of nested ternary?
@Marmiz i don't think so, i think the instructions are just confusing
or i'm not smart enough to understand them, anyway
Nazar
@IsaakNazar
Mar 28 2018 15:19
@thekholm80 you're genius, thank you :+1:
CamperBot
@camperbot
Mar 28 2018 15:19
isaaknazar sends brownie points to @thekholm80 :sparkles: :thumbsup: :sparkles:
api offline
Kyle Holm
@thekholm80
Mar 28 2018 15:20
@IsaakNazar i don't think my solution is correct, even though it passes
my understanding is, don't assign anything to this.state that doesn't get used in render()
and i didn't use this.state.input
Nazar
@IsaakNazar
Mar 28 2018 15:21
@thekholm80 ok, I'll keep in mind
Sweet Coding :)
@SweetCodingInc
Mar 28 2018 15:23
@thekholm80 but this.state.input is being used in
handleChange(e) {
    this.setState({
      input: e.target.value,
      userAge: ''
    });
  }
from onChange on input
Kyle Holm
@thekholm80
Mar 28 2018 15:23
@SweetCodingInc that's not inside the render() method
Sweet Coding :)
@SweetCodingInc
Mar 28 2018 15:24
@thekholm80 on input value={this.state.input}
Kyle Holm
@thekholm80
Mar 28 2018 15:25
hmm, maybe they really are expecting us to use nested ternaries then
Sweet Coding :)
@SweetCodingInc
Mar 28 2018 15:26
What's the problem with nested ternaries?
Kyle Holm
@thekholm80
Mar 28 2018 15:26
they're ugly and difficult to understand
Sweet Coding :)
@SweetCodingInc
Mar 28 2018 15:26
anyway.. I can't even get the button to show up with
render() {
  const buttonOne = <button onClick={this.submit}>Submit</button>;
  const buttonTwo = <button>You May Enter</button>;
  const buttonThree = <button>You Shall Not Pass</button>;
  return (
    <div>
      <h3>Enter Your Age to Continue</h3>
      <input
        style={inputStyle}
        type="number"
        value={this.state.input}
        onChange={this.handleChange} /><br />
      {
        this.state.userAge == '' ? <buttonOne/> : this.state.userAge >= 18 ? <buttonTwo/> : <buttonThree/>
      }
    </div>
  );
}
Darren
@DarrenfJ
Mar 28 2018 15:26
monring fCC helpRoom team
Kyle Holm
@thekholm80
Mar 28 2018 15:26
buttonOne etc aren't components, they're variables
@DarrenfJ :wave:
Darren
@DarrenfJ
Mar 28 2018 15:26
how goes thee?
Sweet Coding :)
@SweetCodingInc
Mar 28 2018 15:26
@thekholm80 ah! That's subjective.. I for one find ternaries more readable
Darren
@DarrenfJ
Mar 28 2018 15:27
hey guys :wave: @thekholm80 @SweetCodingInc
Sweet Coding :)
@SweetCodingInc
Mar 28 2018 15:27
@DarrenfJ Ser Darren :wave:
Kyle Holm
@thekholm80
Mar 28 2018 15:27
most 'best practice' guides i've seen re: ternaries say don't ever nest more than 2 deep
Sweet Coding :)
@SweetCodingInc
Mar 28 2018 15:28

@thekholm80

Yeah.. my bad.. It worked now

render() {
  const buttonOne = <button onClick={this.submit}>Submit</button>;
  const buttonTwo = <button>You May Enter</button>;
  const buttonThree = <button>You Shall Not Pass</button>;
  return (
    <div>
      <h3>Enter Your Age to Continue</h3>
      <input
        style={inputStyle}
        type="number"
        value={this.state.input}
        onChange={this.handleChange} /><br />
      {
        this.state.userAge == '' ? buttonOne : this.state.userAge >= 18 ? buttonTwo : buttonThree
      }
    </div>
  );
}
Kyle Holm
@thekholm80
Mar 28 2018 15:28
@DarrenfJ how's the great, frozen north?
Darren
@DarrenfJ
Mar 28 2018 15:33
we're finally getting a thaw
Kyle Holm
@thekholm80
Mar 28 2018 15:34
does that mean curling season is over?
Darren
@DarrenfJ
Mar 28 2018 15:34
curling season is NEVER over!
;)
Kyle Holm
@thekholm80
Mar 28 2018 15:34
lol
i have some friends from Alberta, they live for curling
well, watching it on tv anyway
Darren
@DarrenfJ
Mar 28 2018 15:35
curling's fun.. it's like baseball in that it's one of those games you can be in left field drinking a beer and still be ok at it
you can pull out your lawn chair and take a nap in the middle of the 6th inning
Kyle Holm
@thekholm80
Mar 28 2018 15:36
lol
i watch & play golf ... very rare to see people play without beer
Darren
@DarrenfJ
Mar 28 2018 15:38
that's true too...
but with golf you still have to play.. with curling you have like 4 teammates so unless yer a sweeper you spend a lot of down time... and Baseball... man. you can go innings without seeing a ball..
Kyle Holm
@thekholm80
Mar 28 2018 15:39
very true
Darren
@DarrenfJ
Mar 28 2018 15:39
that said, i'm off to test! tra-la!
DarrenfJ @DarrenfJ sneaks off to test
Nazar
@IsaakNazar
Mar 28 2018 15:48
@thekholm80 is it correct counter?
handleClick() {
    this.setState(prev => {
      counter: prev+this.state.counter // change code here
    });
  }
@thekholm80 I got it
@thekholm80 how to make it without return ?
handleClick() {
    this.setState(prev => {
      return {counter: prev.counter+1} // change code here
    });
  }
Kyle Holm
@thekholm80
Mar 28 2018 16:19
you don't need to use a callback inside setState() you can assign directly @IsaakNazar
oh, don't listen to me
i assume you're doing one of their lessons so i don't know what they're asking you
i've not been through the beta react lessons
Nazar
@IsaakNazar
Mar 28 2018 16:28
@thekholm80 thanx :+1:
CamperBot
@camperbot
Mar 28 2018 16:28
isaaknazar sends brownie points to @thekholm80 :sparkles: :thumbsup: :sparkles:
:star2: 1751 | @thekholm80 |http://www.freecodecamp.org/thekholm80
Thanh Son Nguyen
@nguyen-thanhson
Mar 28 2018 16:47
hey everyone. Hope you are having a good day/night
I want to ask, why doesn't this work?
let a = [
  {
    id: "1234",
    qty: 34,
    subtotal: 68
  },
  {
    id: "6789",
    qty: 3,
    subtotal: 90
  }
];

console.log(a.reduce(function(o1, o2) {
  return o1.subtotal + o2.subtotal;
}, { subtotal: 0 }))
while this does?
let a = [
  {
    id: "1234",
    qty: 34,
    subtotal: 68
  }
];

console.log(a.reduce(function(o1, o2) {
  return o1.subtotal + o2.subtotal;
}, { subtotal: 0 }))
jamesgeth
@jamesgeth
Mar 28 2018 17:06
anyone knows what the value of eth.coinbase is
Abdullah
@AbdullahChaudhry
Mar 28 2018 17:26
@nguyen-thanhson Solved it

@nguyen-thanhson Basically, when using the reduce function the o1 in your code is the accumulator, this means when you do the return command, it will assign the total back to o1.

For the first iteration this is fine, because it's just going to take your subtotal: 0 value and add it to subtotal of the first object.

However, if you supply more than one object to that array, after the first iteration, o1 will not be an object, it will be a number. And in your code you are trying to access subtotal of o1, a property that doesn't exist.

You should therefore be returning an object with the total like this:

return { subtotal: o1.subtotal + o2.subtotal }

This way it can access the subtotal from the accumulator

reduce-debugger.png
Abdullah
@AbdullahChaudhry
Mar 28 2018 17:36
a.reduce((acc, curr) => {
  return { subtotal: acc.subtotal + curr.subtotal }
}, { subtotal: 0})
You could then access the resulting subtotal value from the returned object
Forgot to mention, trying to access subtotal on a number will give you undefined, you are then adding a number to undefined, which is why it's returning NaN (not a number)
DucNguyen
@Trungduc3336
Mar 28 2018 19:53
hey guys, can you help me with this problem?

<style>

.red-text
{
color: red;
font-size: 16px;
}

</style>

<h2 class="red-text">CatPhotoApp</h2>

<p class="red-text">Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>

<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>

I try to zoom in, zoon out, But it didnt work? this is my error: Between the style tags, give the p elements font-size of 16px. Browser and Text zoom should be at 100%.
May Kittens Devour Your Soul
@diomed
Mar 28 2018 19:54
@Trungduc3336 zoom has nothing to do with it
Kyle Holm
@thekholm80
Mar 28 2018 19:54
did you give your p elements font-size: 16? or did you give that to your class 'red-text'?
DucNguyen
@Trungduc3336
Mar 28 2018 19:56
@thekholm80

<style>

.red-text
{
color: red;
}
.p
{
font-size: 16px;
}
</style>

<h2 class="red-text">CatPhotoApp</h2>

<p class="red-text">Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>

<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>

Kyle Holm
@thekholm80
Mar 28 2018 19:56
the . means 'class'
May Kittens Devour Your Soul
@diomed
Mar 28 2018 19:56
@Trungduc3336 p is not a class
Kyle Holm
@thekholm80
Mar 28 2018 19:56
but you're almost there
DucNguyen
@Trungduc3336
Mar 28 2018 19:56
ohhhhhhhhhhhhhhh
So what is "p"?
Kyle Holm
@thekholm80
Mar 28 2018 19:57
an element
DucNguyen
@Trungduc3336
Mar 28 2018 19:57
Oh, I got it
tks mate
Kyle Holm
@thekholm80
Mar 28 2018 19:58
<style>
p {
  // this selects all <p> tags in your html
}
.myClass {
  // this selects all elements with class='myClass'
}
#myID {
  // this selects the element with id='myID'
}
</style>
@Trungduc3336
Kyle Holm
@thekholm80
Mar 28 2018 20:20
@diomed x
May Kittens Devour Your Soul
@diomed
Mar 28 2018 20:23
oh wow! never thought of that
Azucena Martinez
@azucenareyes
Mar 28 2018 22:03
Hello! Does anyone know how to use firebase to deploy an app? I am 90% there just having a problem with my index.html
Kyle Holm
@thekholm80
Mar 28 2018 22:04
@azucenareyes are you using the firebase cli?
Azucena Martinez
@azucenareyes
Mar 28 2018 22:04
yes!
Kyle Holm
@thekholm80
Mar 28 2018 22:04
what happens when you deploy?
Azucena Martinez
@azucenareyes
Mar 28 2018 22:04
It actually does deploy my app, but it shows the standard index.html welcome page
Just the index.html welcome page
I need to figure out how to have it show my app.
Kyle Holm
@thekholm80
Mar 28 2018 22:05
one sec, i haven't used firebase in a lot of months. i'm looking at my console
Azucena Martinez
@azucenareyes
Mar 28 2018 22:05
@thekholm80 thank you
CamperBot
@camperbot
Mar 28 2018 22:05
azucenareyes sends brownie points to @thekholm80 :sparkles: :thumbsup: :sparkles:
:star2: 1752 | @thekholm80 |http://www.freecodecamp.org/thekholm80
Kyle Holm
@thekholm80
Mar 28 2018 22:07
ugh i can't see any way to view logs
life got so much better when i switched to heroku lol
Azucena Martinez
@azucenareyes
Mar 28 2018 22:08
Well, to give you some background, I'm using create-react-app and it gives you a 'build' folder.
This folder gives you an index.html page but it's not what I need to see when I deploy.
Kyle Holm
@thekholm80
Mar 28 2018 22:09
is your project on github?
just might help to see what you're talking about
Azucena Martinez
@azucenareyes
Mar 28 2018 22:09
Yes
Let me send you the link
Kyle Holm
@thekholm80
Mar 28 2018 22:10
LObeautyArt?
Azucena Martinez
@azucenareyes
Mar 28 2018 22:10
yes, what?
That's cool
Kyle Holm
@thekholm80
Mar 28 2018 22:10
you logged into gitter through github, so you're linked lol
hover over my picture, you can go to my github lol
Azucena Martinez
@azucenareyes
Mar 28 2018 22:11
Oh nice!!
I see now!
Anyway the problem just lies/lyes? with the index.html and how to set it to show my app. Do you recommend Heroku instead?
Kyle Holm
@thekholm80
Mar 28 2018 22:13
if it's just a SPA i'd still use firebase
if you use heroku you'll have to build a back end too
so the index.html in your build folder isn't the correct index.html?
Azucena Martinez
@azucenareyes
Mar 28 2018 22:15
Well i'm new to react and I use the create-react-app feature.
Kyle Holm
@thekholm80
Mar 28 2018 22:15
okay, so you used npm run build or yarn build to bundle your app
Azucena Martinez
@azucenareyes
Mar 28 2018 22:15
I do all my work in index.js and the index.html is already there
Yes
Kyle Holm
@thekholm80
Mar 28 2018 22:16
just a sec i'm reading through the CRA firebase walkthrough
weird. seems like it should just work. can you share the link to the hosted project on firebase?
Azucena Martinez
@azucenareyes
Mar 28 2018 22:19
Yes!!
Kyle Holm
@thekholm80
Mar 28 2018 22:20
oh, no i need the actual web link
will look something like
Kyle Holm
@thekholm80
Mar 28 2018 22:21
ah
did you get any errors in the console when you deployed?
Azucena Martinez
@azucenareyes
Mar 28 2018 22:22
No, I can send you screenshots
Kyle Holm
@thekholm80
Mar 28 2018 22:22
could help
Azucena Martinez
@azucenareyes
Mar 28 2018 22:22
How do you go to personal messaging?
Kyle Holm
@thekholm80
Mar 28 2018 22:23
hover over my pic and click Chat Privately