Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 17:13
    @mstellaluna banned @cmal
  • Jan 08 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
  • Jul 29 2018 01:00
    @bjorno43 banned @jkyereh
  • Jul 10 2018 22:09
    @bjorno43 banned @manafn
  • Jul 06 2018 15:20
    @texas2010 banned @imlegend19
  • Jul 03 2018 12:28
    @bjorno43 banned @vbvmatta
  • Jun 29 2018 13:54
    @bjorno43 banned @OGTechnoBoy
Muhammed Hafiz
@zifahm
@sjames1958gm thanks again
CamperBot
@camperbot
zifahm sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8863 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Stephen James
@sjames1958gm
:+1:
Brandon Blackwell
@Radlerz1
hello, I am using react with redux its my first time using redux. I am calling an api in my react component then sending that data from my component to the redux store so I can access it throughout all components. My question is would it be better to call a function in redux from my react component that executes the api call in the reducer and stores the data in the redux store that way. which way is better ? if there is advantages and disadvantages to both
Joy
@Yorokobi05
Good day! I would just like to ask regarding .indexOf property in JS. I cannot have it returned "false".
Brandon Blackwell
@Radlerz1
indexOf doesn't not return false if there is not match it returns -1 @Yorokobi05
Joy
@Yorokobi05

function mutation(arr) {
for (var i = 0; i < arr[1].length; i++){
var z = (arr[1].toLowerCase()).split("");
var a = (arr[0].toLowerCase()).indexOf(z[i]);
if (a != -1) {
return true;
} else return false;
}

}

mutation(["hello", "hey"]);

I already have this one, however, it returns " true".
Brandon Blackwell
@Radlerz1
what is the question your on?
Joy
@Yorokobi05
Mutation under the Basic Algorithm
Marianissimus
@Marianissimus
@Yorokobi05 else should be // else {return false;}
Stephen James
@sjames1958gm
@Yorokobi05 you shouldn't return true until all the letter have been checked
Marianissimus
@Marianissimus
and why do you use brackets for var a and z?
Aditya
@ezioda004
@Yorokobi05 This one returns true because that index exists. (arr[0].toLowerCase()).indexOf(z[i]) returns a number
Joy
@Yorokobi05
@Marianissimus it's the same. (regarding the else statement) and I think it's fine even if I didn't put it under the for loop.
Stephen James
@sjames1958gm
@Yorokobi05 You should only return for the false case inside the loop - then if the loop finishes without returning false then return true
Joy
@Yorokobi05
Ok. I'll recheck first. Thanks!
Stephen James
@sjames1958gm
@Yorokobi05 A suggestion to take after you get it working:
var z = (arr[1].toLowerCase()).split("");
this code doesn't depend on the loop variables and should be done before the loop as optimization
Joy
@Yorokobi05
@sjames1958gm still don't get it. haha

function mutation(arr) {
var z = (arr[1].toLowerCase()).split("");
for (var i = 0; i < arr[1].length; i++){
var a = (arr[0].toLowerCase()).indexOf(z[i]);
if (a != -1) {
return false;
}
} return true;

}

mutation(["hello", "hey"]);

Stephen James
@sjames1958gm
@Yorokobi05 false is a == -1 not a != -1
Joy
@Yorokobi05
oh, I forgot to replace it.
It's working! Thanks a bunch @sjames1958gm !
CamperBot
@camperbot
yorokobi05 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8864 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Stephen James
@sjames1958gm
:+1:
@Yorokobi05 BTW functions are called left to right so the () around the toLowerCase() call are not needed
var z = arr[1].toLowerCase().split("");
Joy
@Yorokobi05
I see. Thanks @sjames1958gm ! I'll take note of that! :smile:
zipquote
@zipquote
This message was deleted
Javier Pons
@JavierPons
hi folks!
I have typed this code
function centuryFromYear(year) {
    if (year <= 100) {
        return '1';
    }else if (year > 101 && year <= 200) {
        return '2';
    }else if (year > 201 && year <= 300) {
        return '3';
    }else if (year > 301 && year <= 400) {
        return '4';
    }else if (year > 401 && year <= 500) {
        return '5';
    }else if ( year > 501 && year <= 600) {
        return '6';
    }else if ( year > 601 && year <= 700) {
        return '7';
..... and carry on.....
sure that its possible to type it in shorter way. Any advise?
Kaz Baig
@kbaig
@JavierPons
function centuryFromYear(year) {
  return Math.ceil(year / 100);
}
assuming you actually wanted year >= 101 to be 2 rather than year > 101
Though shouldn't it be < 100 returning 1, <= 200 && >= 100 returning 2 etc
In which case, it would be
function centuryFromYear(year) {
  return Math.floor(year / 100) + 1;
}
Javier Pons
@JavierPons
@kbaig Given a year, return the century it is in. That is the purpose
Kaz Baig
@kbaig
Right, but < year 100 is the first century
Year 100 is in the second century, no?
Javier Pons
@JavierPons
in this case we count 100 inside 1 century
Kaz Baig
@kbaig
Oh I'm mistaken, 100 is part of the 1st century
kk Math.ceil(year / 100) it is then
Javier Pons
@JavierPons
@kbaig no, it doesn't work
Kaz Baig
@kbaig
What case is it not satisfying?
Javier Pons
@JavierPons
anyone
:worried:
aRtoo
@artoodeeto
hello fam. i have a question? how can i make my modal center in my tictactoe game while it changes screen size? the game is done but i want to style it more. thanks. heres the pen. https://codepen.io/artoo/pen/Zvomxr?editors=0100