These are chat archives for FreeCodeCamp/HelpJavaScript

3rd
Jan 2018
Fate
@420101332
Jan 03 2018 02:43 UTC
function largestOfFour(arr) {
        // 请把你的代码写在这里
        var len = arr.length;
        var newarr = [];
        for(var i = 0; i < len; i++) {

            newarr.push(Math.max.apply(null, arr[i]));

        }


        return newarr;
    }

    largestOfFour([
        [4, 5, 1, 3],
        [13, 27, 18, 26],
        [32, 35, 37, 39],
        [1000, 1001, 857, 1]
    ]);
这个哪里有错吗.. 为什么过不了..
Joel Y.
@zapcannon99
Jan 03 2018 02:56 UTC
do you need .apply?
Fate
@420101332
Jan 03 2018 02:57 UTC
Why not ?
I refreshed the page problem, and it didn't matter with the code.
Ken Haduch
@khaduch
Jan 03 2018 02:59 UTC
@420101332 - your code appears to work, was it just a page caching issue?
Fate
@420101332
Jan 03 2018 03:00 UTC
yes
The code itself has no problem
Ken Haduch
@khaduch
Jan 03 2018 03:00 UTC
That's good, sorry I couldn't read the Chinese writing...
Joel Y.
@zapcannon99
Jan 03 2018 03:00 UTC
@420101332 yeah i read the docs youre fine
Fate
@420101332
Jan 03 2018 03:00 UTC
it's ok
Joel Y.
@zapcannon99
Jan 03 2018 03:01 UTC
huh weird
let me plug it in
hmm works
aRtoo
@artoodeeto
Jan 03 2018 03:07 UTC
hey guys'
Claudio Restifo
@Marmiz
Jan 03 2018 03:18 UTC
:wave:
Ken Haduch
@khaduch
Jan 03 2018 03:41 UTC
@artoodeeto :wavy_dash: :wave: :wavy_dash:
aRtoo
@artoodeeto
Jan 03 2018 03:41 UTC
@khaduch hello sir can i pm u?
hello. how i can call a return function?
have this code. and i want it to return a clearInterval
Ken Haduch
@khaduch
Jan 03 2018 03:45 UTC
@artoodeeto - lf you want to, but you could just ask questions here and more people can get a chance to offer help...
aRtoo
@artoodeeto
Jan 03 2018 03:45 UTC
when i press a button
 var timerFn = function timer(minutes,seconds) {

        // console.log(typeof minutes); //checking type of data. needs to be a number
        // console.log(minutes, seconds);

        $('#min').text(minutes); //min.innerHTML = minutes;  
        $('#secs').text(seconds);   //sec.innerHTML = seconds;

        var counter = setInterval(setIntervalFunction,10);

        function setIntervalFunction() {

            // console.log(seconds--);

            $('#secs').text(seconds-=1); //secs.innerHTML = seconds-=1; //reduced seconds by 1;

            if(minutes > 0 && seconds === 0){ //condition if seconds is 0;

                // console.log("min:" , minutes-=1);

                $('#min').text(minutes-=1); //min.innnerHTML = minutes-=1; //reduced minutes by 1; //issue: doesnt display.

                seconds = 60; // revalues seconds
            } 

            else if(minutes === 0 && seconds === 0) { //condition to check if minutes is 0, then passes a new value of minutes in timer function.

                clearInterval(counter);

                if (brkVal > 0) {
                    timerFn(brkVal, 60);
                    brkVal  = 0;
                    // console.log('breakVAL:' , brkVal);
                }
            }

        }

        return function clearTimer() {
            clearInterval(counter);
        }

    }


    /* RESET button */
    $("#btnRes").on('click', function() {
        timerFn();
    })    

});
@khaduch hello sir. so i tried calling the timerFn() but it wont stop the timer from running
any idea?
Ken Haduch
@khaduch
Jan 03 2018 03:47 UTC
@artoodeeto - don't you want to call clearTimer() when you click? Because calling timerFn()looks to be starting another timer... one thing that you probably need to do is make your counter variable scope to be accessible outside of timerFn so that the clearTimer() can access it.
aRtoo
@artoodeeto
Jan 03 2018 03:49 UTC
@khaduch ohh shit i knew it. it will run the function inside. hmmm. any idea how would i stop the timer without making it global?
scarejar
@scarejar
Jan 03 2018 03:49 UTC
return the the counter and run clearTimer(counter) I would think, on the click handler
aRtoo
@artoodeeto
Jan 03 2018 03:51 UTC
@khaduch if i make it global it will run immediately right?
@scarejar i think it will still trigger the whole code to run another timer function
Ken Haduch
@khaduch
Jan 03 2018 03:52 UTC

@artoodeeto - you have to watch out for one big thing - you have to make sure that you do not start multiple timers unless you keep track of all of the setInterval return values in some way so that you can stop everything when you need to. But in all likelihood, starting multiple timers is a bug in this application, no? I make my counter variable global. I maintain the state of it by initially setting it to null, and only start a timer if counter === null and after stopping the timer, clear counter.

No, your timer won't run until you start it - having the variable "global" in scope won't start the timer.

aRtoo
@artoodeeto
Jan 03 2018 03:56 UTC
@khaduch it wasnt supposed to be a multiple timer running. its supposed to be one timer only. its just that i need to access the clearInterval inside the timer function. the original code is this.
 function timer(minutes,seconds) {

        // console.log(typeof minutes); //checking type of data. needs to be a number
        // console.log(minutes, seconds);

        $('#min').text(minutes); //min.innerHTML = minutes;  
        $('#secs').text(seconds);   //sec.innerHTML = seconds;

        var counter = setInterval(setIntervalFunction,10);

        function setIntervalFunction() {

            // console.log(seconds--);

            $('#secs').text(seconds-=1); //secs.innerHTML = seconds-=1; //reduced seconds by 1;

            if(minutes > 0 && seconds === 0){ //condition if seconds is 0;

                // console.log("min:" , minutes-=1);

                $('#min').text(minutes-=1); //min.innnerHTML = minutes-=1; //reduced minutes by 1; //issue: doesnt display.

                seconds = 60; // revalues seconds
            } 

            else if(minutes === 0 && seconds === 0) { //condition to check if minutes is 0, then passes a new value of minutes in timer function.

                clearInterval(counter);

                if (brkVal > 0) {
                    timer(brkVal, 60);
                    brkVal  = 0;
                    // console.log('breakVAL:' , brkVal);
                }
            }

        }

    }


    /* RESET button */
    $("#btnRes").on('click', function() {

    })    

});
@khaduch that one sir. but theres no way to access the counter variable on my reset button
Ken Haduch
@khaduch
Jan 03 2018 04:01 UTC
@artoodeeto - the way that the code appears to me, any time you run timer() it will start another interval timer. How are you kicking this off - where do you invoke timer()? Is it a click handler on another button? You have to have the value of counter - the return from the setInterval() in a place where you can access it when you need to - as I said above, the way I use it is if the variablecounter has a value, then it means that a setInterval timer was started, and I don't want to start another one. As long as you maintain the value in counter in sync with the state of whether or not you have a timer running, you can use it to control the startup of a timer, or prevent the startup of a second timer, and also use it to clearInterval(counter); and then counter = null; after that to indicate that the counter has been stopped.
aRtoo
@artoodeeto
Jan 03 2018 04:02 UTC
@khaduch im sorry i forgot to remove the return function.
it has a clearInterval inside else if statement
the timer is triggered by a button.
@khaduch heres the pen if you want to see it sir. thanks
CamperBot
@camperbot
Jan 03 2018 04:04 UTC
artoodeeto sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3642 | @khaduch |http://www.freecodecamp.org/khaduch
Ken Haduch
@khaduch
Jan 03 2018 04:17 UTC
@artoodeeto - your reset button has a handler named timerFn() but there is no function with that name?
scarejar
@scarejar
Jan 03 2018 04:19 UTC
lol, I can't seem to work around a global
aRtoo
@artoodeeto
Jan 03 2018 04:20 UTC
@khaduch o dont mind that sir. i forgot to delete it again. it was meant for my function declaration.
scarejar
@scarejar
Jan 03 2018 04:21 UTC

    /* START button */
let pomoTimer;
    $("#btnPly").on('click', function() {
        pomoTimer = timer(sesVal, 60);
    })

    /* Single Function for timer */

function timer(minutes,seconds) {

        // console.log(typeof minutes); //checking type of data. needs to be a number
        // console.log(minutes, seconds);

        $('#min').text(minutes); //min.innerHTML = minutes;  
        $('#secs').text(seconds);   //sec.innerHTML = seconds;

        var counter = setInterval(setIntervalFunction,100);

        function setIntervalFunction() {

            // console.log(seconds--);

            $('#secs').text(seconds-=1); //secs.innerHTML = seconds-=1; //reduced seconds by 1;

            if(minutes > 0 && seconds === 0){ //condition if seconds is 0;

                // console.log("min:" , minutes-=1);

                $('#min').text(minutes-=1); //min.innnerHTML = minutes-=1; //reduced minutes by 1; //issue: doesnt display.

                seconds = 60; // revalues seconds
            } 

            else if(minutes === 0 && seconds === 0) { //condition to check if minutes is 0, then passes a new value of minutes in timer function.

                clearInterval(counter);

                if (brkVal > 0) {
                    timer(brkVal, 60);
                    brkVal  = 0;
                    // console.log('breakVAL:' , brkVal);
                }
            }

        }
  return counter;
    }


    /* RESET button */
    $("#btnRes").on('click', function() {
         clearInterval(pomoTimer);
    })    

});
I think there's no way around it? Everytime you call timer, you create a new instance and I'm not entirely sure how to refference an old instance without setting an outside variable
Ken Haduch
@khaduch
Jan 03 2018 04:24 UTC
@artoodeeto - I can try to make some modifications and fork your project to show you what I would do to fix it. But it looks like you want to do something like @scarejar is showing - make a variable that has a scope that is accessible to your timerand your clearInterval() function. I would suggest again that you use the value of that to determine whether or not you have a timer running so that you do not start another. I could edit the pen that you shared and show you what I would do, but this post and my previous posts is a description of what I would do.
aRtoo
@artoodeeto
Jan 03 2018 04:29 UTC
@scarejar let me try this sir.
@khaduch for sure sir. anything will help. thanks
CamperBot
@camperbot
Jan 03 2018 04:30 UTC
artoodeeto sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
api offline
aRtoo
@artoodeeto
Jan 03 2018 04:35 UTC
@khaduch hey sir its working now but theres still a bug. but ill try to fix myself first before im gonna ask for help. care to explain what you did?? would appreciate it sir. thanks
CamperBot
@camperbot
Jan 03 2018 04:35 UTC
artoodeeto sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
api offline
Ken Haduch
@khaduch
Jan 03 2018 04:57 UTC
@artoodeeto - here is a basic version of your pen with the changes that allow you to start the timer, then reset stops the timer. I changed the variable name to interval and declared it at the top with your other "globals" for the time values. Once a timer is started, interval is set to the ID that is returned from the setInterval call, and from then on it will not allow another timer to be started until it is cleared. The handler for the reset button just clears the timer, and clears the variable. So you can start another timer - you can decide what other actions are appropriate, such as restoring the time display to the initial count, etc. But it's working to a point where it does something reasonable with the interval timer to start only one, and then stop the one that is running and clear the interval variable as needed.
aRtoo
@artoodeeto
Jan 03 2018 04:59 UTC
@khaduch let me check sir. thank you. appreciate ur time and effort
CamperBot
@camperbot
Jan 03 2018 04:59 UTC
artoodeeto sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
api offline
张海峰
@zhanghaifeng213
Jan 03 2018 08:43 UTC
help

Search and Replace
使用给定的参数对句子执行一次查找和替换,然后返回新句子。

第一个参数是将要对其执行查找和替换的句子。

第二个参数是将被替换掉的单词(替换前的单词)。

第三个参数用于替换第二个参数(替换后的单词)。

注意:替换时保持原单词的大小写。例如,如果你想用单词 "dog" 替换单词 "Book" ,你应该替换成 "Dog"。

如果你被难住了,记得使用 Read-Search-Ask尝试与他人结伴编程、编写你自己的代码。

这是一些对你有帮助的资源:

Long Nguyen
@longnt80
Jan 03 2018 08:49 UTC
张海峰
@zhanghaifeng213
Jan 03 2018 08:50 UTC
thanks
Anabel
@AnabelSalomone
Jan 03 2018 09:50 UTC

Hello guys! :) I need help with this: I need to find a function to replace the text between brackets into another text/function. Example:

[01[myName][mySurname]02]

And I will get this

01FooBar02

any idea?

Thomas Faller
@thomasfaller
Jan 03 2018 09:54 UTC

Hey guys, just for fun's sake I made a little PIN-guessing game (kinda simple Mastermind game if you know it)
https://codepen.io/thomasfaller/pen/PEzOVd

What kind of improvements could I make in terms of how the code is written / structured?

Marianissimus
@Marianissimus
Jan 03 2018 09:59 UTC
@thomasfaller hi, it seems nice, but i cant seem to be able to win... i've got the last 3 digits, but always an error on 1st: x631
Markus Kiili
@Masd925
Jan 03 2018 10:03 UTC
@thomasfaller I don't see the point of that getPin IIFE, when you execute a function that returns a function that always returns the same array. I would get it if you made a function that returned a new random pin array with each call.
Thomas Faller
@thomasfaller
Jan 03 2018 10:23 UTC
Good point @Masd925 Thanks
CamperBot
@camperbot
Jan 03 2018 10:23 UTC
thomasfaller sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4635 | @masd925 |http://www.freecodecamp.org/masd925
Thomas Faller
@thomasfaller
Jan 03 2018 10:23 UTC
Thanks @Marianissimus
CamperBot
@camperbot
Jan 03 2018 10:23 UTC
thomasfaller sends brownie points to @marianissimus :sparkles: :thumbsup: :sparkles:
:cookie: 451 | @marianissimus |http://www.freecodecamp.org/marianissimus
Pieter Stokkink
@forkerino
Jan 03 2018 10:44 UTC
@thomasfaller I encountered the same problem where I had 3 correct and none of the digits worked for the last one.
Markus Kiili
@Masd925
Jan 03 2018 10:45 UTC
@forkerino Yo.
Pieter Stokkink
@forkerino
Jan 03 2018 10:45 UTC
@Masd925 Hey! Happy new year!
Markus Kiili
@Masd925
Jan 03 2018 10:45 UTC
@forkerino Same to you :sparkles:
@forkerino What are the big goals this year for you?
Pieter Stokkink
@forkerino
Jan 03 2018 11:11 UTC
More dancing, more laughing, more good healthy food, more movement. Professionally: just get better at programming, but that will happen almost by itself. @Masd925
Anabel
@AnabelSalomone
Jan 03 2018 11:11 UTC

@AnabelSalomone
I reformulate my question, so maybe it will be clearer:

Having this string "abc[def][ghi]jkl"

I would like to find a way to replace all the instances of text between brackets by something like "1[text]1" in order to have as a result "abc1def11ghi1jkl"
the regex to find text between brackets is /[(.*?)]/g
It is not that I only want to replace the brackets by 1's, but to wrap the text with any text I want

Markus Kiili
@Masd925
Jan 03 2018 11:16 UTC
@forkerino For me: 70 bjj drills (~20 last year), 70. on national chess rating list (81. now), 7 minutes breath hold (6:17 last year), 7 kg more muscle (lost 7 kg fat last year).
Pieter Stokkink
@forkerino
Jan 03 2018 12:15 UTC
:clap:
Blauelf
@Blauelf
Jan 03 2018 12:54 UTC
@AnabelSalomone So the brackets might contain additional [ in between?
@AnabelSalomone Does .replace(/\[(.*?)\]/g, (_, p1)=>"1"+p1+"1") work in your sense?
Diego Mayer
@Chrono79
Jan 03 2018 12:59 UTC
More like .replace(/\[(.*?)\]/g, (_, p1)=>someString+p1+someString) where someString contains a value of your choice
Happy new year to you all
Blauelf
@Blauelf
Jan 03 2018 13:02 UTC
@Masd925 As long as you don't show around your bjj killing moves when you're drunk, like a friend of mine does :P (I don't trust he's able to just pretend at that stage, but he's confident he can)
Markus Kiili
@Masd925
Jan 03 2018 13:07 UTC
@Blauelf I have this sober 40-50 age period going, so that will be easy.
Anabel
@AnabelSalomone
Jan 03 2018 13:46 UTC

In fact what i want to do is get he text between brackets to insert it as the parameter of a function.
Therefore, what i want is something like this:

Having this string:

"01-[getText1][getText2]-34"

or this one:

[getText1]-34[getText2]

I want to generate something like this:

"01-" + Data.GetValue("getText1") + Data.GetValue("getText2")+ "-34"

It is quite hard to explain, so I understand it might be a bit hard to understand the problem

(thanks for helping :) )

Diego Mayer
@Chrono79
Jan 03 2018 13:53 UTC
stringVar.replace(/\[(.*?)\]/g, (_, p1)=>Data.GetValue(p1) like that?
var stringVar = "01-[getText1][getText2]-34";
var data = {};
data.getValue = function(s) {
  return s[0]+s.slice(-1);
}
console.log(stringVar.replace(/\[(.*?)\]/g, (_, p1)=>data.getValue(p1))); //01-g1g2-34
I only copied the names she pasted, but I modified the names of the methods to follow conventions as per @Blauelf request ;)
Blauelf
@Blauelf
Jan 03 2018 14:00 UTC
JavaScript naming conventions would recommend starting both data and getValue with a lowercase letter. Unless they are constructors, which they most likely aren't.
So Object and Math (even though nobody would instantiate Math), but sqrt
Anabel
@AnabelSalomone
Jan 03 2018 14:27 UTC
Yes, I know :) Data.GetValue are internal functions we use in a local framework we created
Data.GetValue("nameOfAField") retrives the value of a field
so what I'm trying to do is basically replace the text between brackets by the value of those fields
Marko Despotovic
@mads87
Jan 03 2018 14:45 UTC
can some1 plz help me with my code?I dont understand whats the problem and why it isnt working

var counter = 5;

while(counter <= 50) {
if(counter % 5 === 0 && counter % 3 === 0){
console.log(counter);
counter+=1;
}
}

i want the loop to console display numbers btw 5 and 50 which can be divided with 5 and 3
Diego Mayer
@Chrono79
Jan 03 2018 14:47 UTC
@mads87 counter will only increase if counter is a multiple of 15, it starts as 5 that it isn't a multiple so it never changes, that's an infinite loop
move counter+=1;below the } that closes the if
Marko Despotovic
@mads87
Jan 03 2018 14:48 UTC
I guessed that its a infinite loop i just couldnt grasp what the issue was :)
Ty so much Diego i have been bashing my head for the last hour or so :)
Diego Mayer
@Chrono79
Jan 03 2018 14:50 UTC
no problem :+1:
Henry
@GitHub-Henry
Jan 03 2018 15:14 UTC
@thomasfaller each number was tried and rejected for slot 1
image.png
Blauelf
@Blauelf
Jan 03 2018 15:23 UTC
Maybe it's hexadecimal and the digit is a? :P
@GitHub-Henry If you type code or getPin() in the console in the game's frame, what does the array contain?
Henry
@GitHub-Henry
Jan 03 2018 15:31 UTC
@Blauelf @thomasfaller
image.png
Blauelf
@Blauelf
Jan 03 2018 15:33 UTC
Interesting. Which browser?
Henry
@GitHub-Henry
Jan 03 2018 15:34 UTC
chrome
Blauelf
@Blauelf
Jan 03 2018 15:34 UTC
Worked with my Chrome, my Firefox, even Internet Exploder.
Henry
@GitHub-Henry
Jan 03 2018 15:36 UTC
@Blauelf i had to open a new tab to answer your question, so the problem was repeatable for me
Diego Mayer
@Chrono79
Jan 03 2018 15:36 UTC
@Blauelf shouldn't each digit be unique?
Blauelf
@Blauelf
Jan 03 2018 15:37 UTC
What do you mean?
Diego Mayer
@Chrono79
Jan 03 2018 15:37 UTC
7227 seems a problem
the 5 is repeated in @GitHub-Henry example (5315)
Blauelf
@Blauelf
Jan 03 2018 15:39 UTC
Yes, I just could reproduce it myself. Problem lies in checkSol, with the ugly nested loops. On repeats, it would / all copies but the last of that value.
@thomasfaller You could fix the duplicate digit problem with a break; after the result[i] = '0'; (or restructure your loops)
Diego Mayer
@Chrono79
Jan 03 2018 15:45 UTC
Or make the digits unique ;)
Thomas Faller
@thomasfaller
Jan 03 2018 15:47 UTC
nice one @Blauelf thanks will check that
CamperBot
@camperbot
Jan 03 2018 15:47 UTC
thomasfaller sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4670 | @blauelf |http://www.freecodecamp.org/blauelf
Diego Mayer
@Chrono79
Jan 03 2018 15:49 UTC
Or add a note saying the digits could be repeated (it seems confusing to me)
Blauelf
@Blauelf
Jan 03 2018 15:49 UTC
I wonder whether a code "1234" and a guess "1111" should result in "0///".
Diego Mayer
@Chrono79
Jan 03 2018 15:50 UTC
I would go for the unique digits way, seems simpler
Henry
@GitHub-Henry
Jan 03 2018 15:50 UTC
@Blauelf i thought not, unless there was a repeating digit
Diego Mayer
@Chrono79
Jan 03 2018 15:52 UTC
@Blauelf that's the answer, yes 1111 => 0/// when code is [1,2,3,4]
Blauelf
@Blauelf
Jan 03 2018 15:57 UTC

Maybe something like

function checkSol(guess) {
  var arr = guess.split("");
  var result = ["x", "x", "x", "x"];
  for (var i = 0; i <= 3; i++) {
    if (arr[i] == code[i]) {
      result[i] = "0";
    }
  }
  var remainingDigits = code.filter((_, i) => result[i] === "x");
  for (var i = 0; i <= 3; i++) {
    if (result[i] == "x" && remainingDigits.indexOf(arr[i]) !== -1) {
      result[i] = "/";
    }
  }
  var resultString = result.join("");
  var node = document.createElement("li");
  var textnode = document.createTextNode(guess + " => " + resultString);
  node.appendChild(textnode);
  document.getElementById("list").appendChild(node);
}

is better, since it only searches digits that aren't already matching?

Jason Luboff
@JLuboff
Jan 03 2018 16:04 UTC
:wave:
Diego Mayer
@Chrono79
Jan 03 2018 16:04 UTC
:wave:
Jason Luboff
@JLuboff
Jan 03 2018 16:06 UTC
How's it going?
Diego Mayer
@Chrono79
Jan 03 2018 16:07 UTC
Tired as always
Jason Luboff
@JLuboff
Jan 03 2018 16:07 UTC
I feel you
Diego Mayer
@Chrono79
Jan 03 2018 16:08 UTC
I can imagine, with the baby and all
Jason Luboff
@JLuboff
Jan 03 2018 16:09 UTC
Yup... but its all good
Diego Mayer
@Chrono79
Jan 03 2018 16:09 UTC
:+1:
later :wave:
Jason Luboff
@JLuboff
Jan 03 2018 16:09 UTC
See ya
Thomas Faller
@thomasfaller
Jan 03 2018 16:12 UTC
@Blauelf nice
Muhammad Hasham
@MohammadHasham
Jan 03 2018 17:20 UTC
what projects should i initially make to become a mern stack developer?
Brad
@bradtaniguchi
Jan 03 2018 18:15 UTC
@MohammadHasham I personally suggest a clone of something, like a wanna be facebook or something. Or something that will be useful to yourself (even if its only a little useful)
Brian
@BrianCodes33
Jan 03 2018 18:33 UTC
function century(year) {
  if (year < 100) {
    return 1;
  } else {
    return year.toString().substring(0,2);
  }
}
how do i make the else a mathematical expression instead of a concatenation
Kudzu
@czhower
Jan 03 2018 18:37 UTC
you arent using concatenation now... what exactly do you want?
Mark
@vinarius
Jan 03 2018 18:40 UTC
@BrianCodes33 use Number();
function century(year) {
  if (year < 100) {
    return 1;
  } else {
    return year.toString().substring(0,2);
  }
}

var x = century(188);
x = Number(x);

console.log(typeof(x));
Brian
@BrianCodes33
Jan 03 2018 18:41 UTC
function century(year) {
  if (year < 100) {
    return 1;
  }
  else if (year < 1000) {
    let firstTwo = year.toString().substring(0,1);
    return Number(firstTwo) + 1
  } else if (year.toString().substring(2,4) === '00') {
    let firstTwo = year.toString().substring(0,2);
    return Number(firstTwo)
  } else {
    let firstTwo =  year.toString().substring(0,2);
    return Number(firstTwo) + 1
  }
}
Kudzu
@czhower
Jan 03 2018 18:42 UTC
If you want a number, why not just subtract 2000 from it?
return year - 2000;
or you want the first 2.. sorry...
Brian
@BrianCodes33
Jan 03 2018 18:42 UTC
yea..
i solved it.
but if you can think of a way to refactor lemme know
Kudzu
@czhower
Jan 03 2018 18:42 UTC
if yiou want pure math you can do integer divide by 100 then.
ie 2017 integer divide by 100 will yield 20.
Brian
@BrianCodes33
Jan 03 2018 18:43 UTC
hmm nice one
Kudzu
@czhower
Jan 03 2018 18:43 UTC
you can use modulo 100 to check to see if it ends in 00 also
if you use math, almost all yiour code goes waty to a single line
Brian
@BrianCodes33
Jan 03 2018 18:50 UTC
function century(year) {
  return year % 100 === 0 ? year / 100 : Math.floor(year / 100 + 1)
}
lol but kata doesn’t allow me to use math
Kudzu
@czhower
Jan 03 2018 18:54 UTC
looks good though :)
but yiou donrt need check against %0 even
2000 / 100 is still 20
Gersho
@Gersho
Jan 03 2018 18:55 UTC
because 0 is false in JS
Kudzu
@czhower
Jan 03 2018 18:55 UTC
iuts not because of the 0 - its becuase both equations are basically equal
and I would suggest .trunc instead of floor, although for positive numbers wont yield a diff result.
you could also:
parseInt(year / 100);
Gersho
@Gersho
Jan 03 2018 19:00 UTC
that's how centuries work
not
Kudzu
@czhower
Jan 03 2018 19:06 UTC

2000 / 100 = 20

If you want century, simply add to the result +1, if you need to ajdust for the 00 you can -+1 to year first. Simple math

parseInt(year / 100) + 1
abnd yiou can offset year before divide for the 00 account.
parseInt((year - 1) / 100) + 1
That will yield 18 for 1800 and 19 for 1801
Tiago Correia
@tiagocorreiaalmeida
Jan 03 2018 20:50 UTC
so im thinking of implementing react and some database on my portfolio to make it easier to keep updated, where do you hostreact/node projects other than glitch?
Jason Luboff
@JLuboff
Jan 03 2018 20:51 UTC
@tiagocorreiaalmeida Heroku?
But why not glitch?
Tiago Correia
@tiagocorreiaalmeida
Jan 03 2018 20:51 UTC
I have a host and a domain but it doesnt support this kind of things, uh cause of the load time imagine sending a portfolio and having a 20sec load page
the person would probably close it down :\
Jason Luboff
@JLuboff
Jan 03 2018 20:51 UTC
Ah, touche
Heroku you can pay to have it always up if I remember correctly
Tiago Correia
@tiagocorreiaalmeida
Jan 03 2018 20:52 UTC
I would call it a bit expensive
7dolars a month
not sure if is there anything at all less expensive
Jason Luboff
@JLuboff
Jan 03 2018 20:54 UTC
Perhaps AWS? I'm not sure
Gersho
@Gersho
Jan 03 2018 20:54 UTC
i'll assume your service provider doesn't allow you to host your database ? (the db doesn't have to be on the same server as the webserver delivering the react right ?)
Tiago Correia
@tiagocorreiaalmeida
Jan 03 2018 20:57 UTC
@Gersho correct aswell, im still a bit confused but I think by generating the entire bundle in react you dont need a server for nothing it will run normally with a static files
so if this is the case maybe going firebase and avoid having a server can be a solution aswell
but alot of doubts :D
alpox
@alpox
Jan 03 2018 20:58 UTC
@tiagocorreiaalmeida You can also host it on github pages :-)
Gersho
@Gersho
Jan 03 2018 20:58 UTC
even the db ?
alpox
@alpox
Jan 03 2018 20:58 UTC
Well that not
React can be hosted on github pages. not the server
Tiago Correia
@tiagocorreiaalmeida
Jan 03 2018 20:58 UTC
when you build the bundle you dotn need a server correct?
Gersho
@Gersho
Jan 03 2018 20:58 UTC
what kind of db are we talking about anyway ? can't you just hardcode it as an object if it's small ?
alpox
@alpox
Jan 03 2018 20:59 UTC
@tiagocorreiaalmeida Well you do need a server if you have a backend (API)
If you only have a react application there is no need
Of course, if you want to connect to mongo or sql you most likely need a backend. Everything else would either not work or be very insecure
If you can fallback to simple files that would not be the case
Tiago Correia
@tiagocorreiaalmeida
Jan 03 2018 21:01 UTC
how about using firebase
directly on react
alpox
@alpox
Jan 03 2018 21:02 UTC
Hmm probably works too
Tiago Correia
@tiagocorreiaalmeida
Jan 03 2018 21:02 UTC
cause when you generate the bundle the firebase methods and everything will go together with it, the onyl issue I can see is having some password and user information on the middle of the file
alpox
@alpox
Jan 03 2018 21:02 UTC
There you get a database and kind of a backend
I didn't look so deep into firebase
But you would be bound to firebase ofc.
Tiago Correia
@tiagocorreiaalmeida
Jan 03 2018 21:03 UTC
ok allready got an idea of what and how to do it thanks :D
Ronique Ricketts
@RoniqueRicketts
Jan 03 2018 21:34 UTC
hello guys
Tiago Correia
@tiagocorreiaalmeida
Jan 03 2018 21:37 UTC
hey @RoniqueRicketts
Ronique Ricketts
@RoniqueRicketts
Jan 03 2018 21:37 UTC
@tiagocorreiaalmeida how are you man
are you excel savy I wanted to do an advance filter for a simple file
Tiago Correia
@tiagocorreiaalmeida
Jan 03 2018 21:39 UTC
I do know somethings and maybe could help you, lets find out :D but probably @JLuboff knows more than me on this topic not sure
Jason Luboff
@JLuboff
Jan 03 2018 21:58 UTC
Excel? I'm horrible with excel
I can export and modify the data to excel via C# and thats about it
Ronique Ricketts
@RoniqueRicketts
Jan 03 2018 21:58 UTC
@JLuboff rude
dang
Jason Luboff
@JLuboff
Jan 03 2018 21:59 UTC
Just being honest :D
Ronique Ricketts
@RoniqueRicketts
Jan 03 2018 22:00 UTC
I know
Kudzu
@czhower
Jan 03 2018 22:46 UTC
@tiagocorreiaalmeida There are many shared hosting plans out there for $3-$5 a month...
Example: $3.92/mo
https://www.a2hosting.com/web-hosting