These are chat archives for FreeCodeCamp/HelpJavaScript

16th
Jun 2018
Phil
@mremotoo
Jun 16 2018 01:31
image.png
Why does my code not working when it is upon trying on the developer console in Chrome?
Moisés Man
@moigithub
Jun 16 2018 02:07
read the messages on bottom left corner

ie:

should return positive

not number is positive @mremotoo

Ryan Williams
@Ryanwfile
Jun 16 2018 02:10
I am working on a multi level dropdown menu using Bootstrap, Jquery in React and I'm having difficulty closing one of the menu's when another one is selected, how do I go about closing an opened menu when another is selected or the user clicks away from the menus? Here is the codepen, any help is greatly appreciated.
https://codepen.io/Ryanwfile/pen/bMwYam
Greg Duncan
@GregatGit
Jun 16 2018 03:35
@Ryanwfile jquery uses messes with the dom - and react creates a virtual dom. Because of this jquery and react don't go hand-in-hand. Whenever I use react with dropdown menus I try to link it with the local state so that any changes to state will create a re-rendering
If you are new to react be careful not to get stuck on one area. If you can't figure it out - look how someone else has created what you are trying to acheive and decontruct it. I personally wasted a lot time trying to figure out things that other had already done - only to find out in time that I had spent way too long on it.
Mike Haslam
@Ongomobile
Jun 16 2018 04:06

Hey Groovy Guys an Gals I am banging around with redux.

I am trying to figure out the syntax to check if qtyCount is > 0 then if so decrement -1
in my reducer this is how I decrement now
case DECREMENT_COUNT:
return {
...state,
[action.id]: { ...state[action.id], qtyCount: state[action.id].qtyCount - 1 },
};

if I run this it logs the qtyCount just can’t figure out the syntax to check if > 0 then decrement if true
case DECREMENT_COUNT:
return {
...state,
test: console.log(state[action.id].qtyCount),
};

Thanks for having a look
Mike

May Kittens Devour Your Soul
@diomed
Jun 16 2018 06:44
is there some kind of algorithm or some js command that lists all the prime numbers up to a certain value
Aditya
@ezioda004
Jun 16 2018 06:50
@diomed Theres sieve of eratosthenes algorithm that can get you prime numbers till the given number, you'd have to implement your own or can google for someones else implementation.
May Kittens Devour Your Soul
@diomed
Jun 16 2018 06:52
thanks @ezioda004
Ryan Williams
@Ryanwfile
Jun 16 2018 07:28
@GregatGit Thank you, yea I don't want to use Jquery particularly but the best example I could find was from w3c schools and they used bootstrap/jquery
Lario Ivankovic
@LarioStax
Jun 16 2018 13:07

Hey gals an guys!
Could someone explain me why doesn't this code pass the Mutation basic algorithm challenge? It fails on the first test (strings hello and hey)?

function mutation(arr) {
let letters = arr[1].toLowerCase().split("");
return arr[0].toLowerCase().includes(...letters);
}

Thanks in advance :D

Greg Duncan
@GregatGit
Jun 16 2018 13:07
@Ryanwfile go vanillia - it will help your react
@Ongomobile your redux shouldn't do any calculations - it either increments or doesn't - it should do any more than that
Greg Duncan
@GregatGit
Jun 16 2018 13:15
@LarioStax this is meant to return true or false
Lario Ivankovic
@LarioStax
Jun 16 2018 13:19
@GregatGit Yeah, I know. Doesn't it? It passes 8/9 tests. But it returns true for -- mutation(["hello", "hey"]) -- even though there's no "y" in "hello", and I cannot figure out why.
Greg Duncan
@GregatGit
Jun 16 2018 13:22
@LarioStax it looks like you are only checking the first letter
I ran it with lots of endings and it doesn't matter
must be your arr[0]
you probably need to loop through the whole arr and if it get through return true but the moment it doesn't return false
Lario Ivankovic
@LarioStax
Jun 16 2018 13:26
Hm, okay. I managed to solve the challenge with other methods, I just couldn't figure out why this one wasn't working. I thought (...letters) will loop through and check each letter from letters array. Guess not :D Thanks Greg!
Greg Duncan
@GregatGit
Jun 16 2018 13:35
@LarioStax :fire:
Mike Haslam
@Ongomobile
Jun 16 2018 13:38
@GregatGit so where do you check if a value is > 0 then decrement if that is the case I only want to decrement if > 0 no need to show -1 in UI
Greg Duncan
@GregatGit
Jun 16 2018 13:43
@Ongomobile before it hits your store
in your react container
@Ongomobile you would have two functions - one tells the redux store to increment - the other to decrement - redux doesn't decide which one to do - it just gets told what to do - which function to call will be decided by the react component/container
Mike Haslam
@Ongomobile
Jun 16 2018 13:46
@GregatGit so here is where decrement gets called <RoundButton onPress={() => this.props.decrement(counter.id)}>-</RoundButton>
@GregatGit I have 2 functions
Greg Duncan
@GregatGit
Jun 16 2018 13:49
you could load the value into local state - if the value > 0 then you call the function - if not you do nothing
I dont recomend it but in your redux if the value is < 0 just return 0
Mike Haslam
@Ongomobile
Jun 16 2018 13:51
here is decrement function decrementCount = (id) => {
this.props.onDecrementCount(id);
};
I have state mapped to props in my class component
I will try to access state locally in decrement function
Mike Haslam
@Ongomobile
Jun 16 2018 13:58
@GregatGit Thanks for help it means a lot to me
my state is an array of objects so kinda of hard to get to
Mike Haslam
@Ongomobile
Jun 16 2018 14:13

@GregatGit thanks got her done really simple now that you explain to me

decrementCount = (id) => {
if (this.props.counters[id].qtyCount > 0) {
this.props.onDecrementCount(id);
}
};

@GregatGit I am starting to see the value of redux
koder3
@koder3
Jun 16 2018 15:01
does anyone know how to use Dark Mode? I turned it on in the settings and it works there but it doesnt work when I'm on a challenge.
Marat
@Marat89bluolyu
Jun 16 2018 15:07
hi all, i many same functions and I want to combine them into one

here is my constants:

const currentName = filters
        .filter(filter => filter.name === 'name' && filter.taskName)
        .reduce((o, key) => ({ ...o, ...key }), {}).taskName;

      const performerId = filters
        .filter(filter => filter.name === 'performerId' && filter.performerId)
        .reduce((o, key) => ({ ...o, ...key }), {}).performerId;

and here i'am apply them:

this.setState({
        name: currentName,
        performerId,
      });
Marat
@Marat89bluolyu
Jun 16 2018 15:15
The problem occurs in the place where I want to point property from array object(taskName or performerId)
Marat
@Marat89bluolyu
Jun 16 2018 15:22

There is my combine function:

getCurrentFilter = name => {
    const filterName = eval(name);
    return this.props.filters
      .filter(filter => filter.name === name && filter.filterName)
      .reduce((o, key) => ({ ...o, ...key }), {}).filterName;
  };

And there I try call it

    const currentName = getCurrentFilter('name')
And i got undefined from filterName
  • Question: How can i get property from filters array object and assign it to const filterName?
Jack Shijin
@Jackshijin
Jun 16 2018 16:32
how to get the value of the object's attribute
Moisés Man
@moigithub
Jun 16 2018 16:36
var myObj = {
  prop1: "val1",
  prop2: "val2"
};
console.log(  myObj.prop1 );  //>>>>>>>>>>>  returns "val1"

Accessing Object Properties with Dot Notation
Accessing Object Properties with Bracket Notation

@Jackshijin

Jack Shijin
@Jackshijin
Jun 16 2018 16:38

var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {

if(myObj.hasOwnProperty("checkProp"))
{
return myObj.checkProp;
}
else{
return "Not Found";
}
}
checkObj("gift");

@moigithub
it doesn't work
I want to return the value of the checkProp
koder3
@koder3
Jun 16 2018 16:40
Hey guys
Moisés Man
@moigithub
Jun 16 2018 16:40
koder3
@koder3
Jun 16 2018 16:41
I just wanted to know: are the advanced algorithm challenges of freecodecamp as hard as the leetcode hard challenges? I was looking to try out leetcode.
Jack Shijin
@Jackshijin
Jun 16 2018 16:44
thanks @moigithub
Simon Cordova
@gbsimon87
Jun 16 2018 21:46
Hey all.
Anybody have a good resource, apart from the docs, that teaches how to correctly lift the state up in React?
Megan Taylor
@megantaylor
Jun 16 2018 22:09
i'm still searching for a good resource for you @gbsimon87, but in my experience, "lifting state up" just means writing a wrapper component for the children components and managing state in the wrapper rather than in the individual child components.
the code in this example might help: https://gerardnico.com/lang/javascript/react/shared_state
koder3
@koder3
Jun 16 2018 22:12
let repeatNum = "42 42 42";
let reRegex = /(^\d{2,})\s\1\s\1$/; // Change this line
let result = reRegex.test(repeatNum);
console.log(result)
can someone please explain what line 2 does and why does this solve the capture groups challenge