These are chat archives for FreeCodeCamp/HelpJavaScript

28th
Jun 2018
Aditya
@ezioda004
Jun 28 2018 00:01
@bvi1994 Modifying change -= currencyValues[bills]; to change = Math.round((change - currencyValues[bills]) * 100)/100 ; should fix the floating point error.
Blauelf
@Blauelf
Jun 28 2018 04:43
Good morning.
Destinatus
@destinatus
Jun 28 2018 05:44
help!
i'm an api/database developer.
i got hired at walmart to do just that.
the day i arrived, manager shows up and claims there's been a personal change.
now i'm writing javascript for react native
javascript is the worst programming language ever concieved.
i'm very unhappy
Blauelf
@Blauelf
Jun 28 2018 06:30
With such misinformation, I would be unhappy, too, especially as they seem to ignore your prior experience or preferences. And even though we are on a JavaScript channel, I somewhat agree with many questionable decisions been made in creating the language (like optional semicolon, or the == operator, or soft-fails introduced because first version had no error handling). But it's here and used everywhere.
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 09:14
Why javascript is bad?
The only thing that annoys me though is that it is case-sensitive which is super annoying because it can create issues in the code if you're not careful enough.
abraham anak agung
@padunk
Jun 28 2018 09:29
@OGTechnoBoy bad in what terms? some programming language is case-sensitive, not just JS.
Blauelf
@Blauelf
Jun 28 2018 09:35
I think worst are the soft-fails. Some of them like accidental creation of global variables have been fixed with strict mode (which should be default), but JavaScript tends to crash long after the actual mistake has happened.
I actually like the case-sensitivity. That way, I know that NUMBER is probably a constant and number is a variable, and those can coexist. Not to be confused with constructor/class Number.
Aditya
@ezioda004
Jun 28 2018 09:59
“There are only two kinds of languages: the ones people complain about and the ones nobody uses.” - Bjarne Stroustrup
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 11:51
@padunk I was talking to Destinatus
Simon Cordova
@gbsimon87
Jun 28 2018 12:05
Good aft :)
Markus Kiili
@Masd925
Jun 28 2018 12:06
:wave:
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 12:20
Guys I really don't understand this challenge:
Can anyone explain it further to me?
Aditya
@ezioda004
Jun 28 2018 12:23
@OGTechnoBoy Theres a pattern in areas, see if you can figure that out (count the blocks). One you figure that pattern out implement it, recursion seems really good here.
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 12:24
Yes but how I'm supposed to find the area?
All what it gives me is the sides n.
I think I found the pattern.
It's the square of n + n-1
Right?
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 12:29
Like, for n = 1, area = 1
n = 2, area = 2*2 + n-1(1) = 5
n = 3, area = 3 3 + n-1(22) = 9 + 4 = 13, I guess?
Aditya
@ezioda004
Jun 28 2018 12:34
You're doing n^2 + (n-1)^2?
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 12:36
Yeah
But I don't think it is the correct pattern, right?
The problem is that "interesting" ruined everything for me.
I don't even what does interesting mean on the challenge.
Aditya
@ezioda004
Jun 28 2018 12:37
Seems correct, for n = 4, 4^2 + (4-1)^2 = 25 which is right.
Its more of a math problem, "Arithmetic Progressions".
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 12:38
Oh yeah! it's correct.
Thanks for your advice!
Aditya
@ezioda004
Jun 28 2018 12:38
:sparkles:
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 12:39
I thought that it needs some algorithm, so I wasted 5 hours searching for some algorithm for it.
While the pattern is clear, I never thought of that. Thank you twice!
Aditya
@ezioda004
Jun 28 2018 12:40
No problem, its fun to solve these kinds of puzzles but yeah its more of a math problem than programming.
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 15:12
Why this doesn't work
function almostIncreasingSequence(sequence) { var bool = []; for(var i = 0; i < sequence.length-1; i++) { sequence.splice(i,1) if((sequence[i+1] - sequence[i]) === -1) { bool = true; } else { bool = false; } } return bool === true; }
Jason Luboff
@JLuboff
Jun 28 2018 15:14
Please use three backticks on seperate lines with code in the middle instead of single backticks when you have multiple lines of code.
function almostIncreasingSequence(sequence) {
   var bool = [];
   for(var i = 0; i < sequence.length-1; i++) {
      sequence.splice(i,1)
      if((sequence[i+1] - sequence[i]) === -1) {
         bool = true;
         }
         else {
         bool = false;
         }
}
   return bool === true;
}
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 15:15
ok
Jason Luboff
@JLuboff
Jun 28 2018 15:16
Also..whats the actual problem, I don't have access to that page
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 15:16

Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array.

Example

For sequence = [1, 3, 2, 1], the output should be
almostIncreasingSequence(sequence) = false;

There is no one element in this array that can be removed in order to get a strictly increasing sequence.

For sequence = [1, 3, 2], the output should be
almostIncreasingSequence(sequence) = true.

You can remove 3 from the array to get the strictly increasing sequence [1, 2]. Alternately, you can remove 2 to get the strictly increasing sequence [1, 3].
Jason Luboff
@JLuboff
Jun 28 2018 15:19
Well.. couple things... while I don't think it'd be an issue, not sure why you assign an array to bool? I would also say to immeditely return false as opposed to assigning it to bool since it would potentially be changed to true on the next loop iteration.
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 15:20
Because if I returned false, it will close the loop and return false on something like 1, 2, -3 which is not right.
Blauelf
@Blauelf
Jun 28 2018 15:20

I remember doing that one :)

BTW, elements don't always differ by exactly 1.

OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 15:20
I tried push() too but it didn't exactly work.
Oh yeah they does.
look at the example
by removing 3, you get [1,2]
So the difference should be 1 between all elements.
If not, then it's false.
Stephen James
@sjames1958gm
Jun 28 2018 15:21
In test 4 they don't differ by just one
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 15:21
Wait, let me see.
Exactly. And when they don't differ by 1. it will return false

Input:

sequence: [1, 4, 10, 4, 2]

Output:

false

Expected Output:

false

Console Output:

Empty

Stephen James
@sjames1958gm
Jun 28 2018 15:22
But that is not the reason that it returns false
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 15:23
I know
by removing 4
It becomes 1,10,4,2
Which is not right.
And by removing, 10, it becomes 1,4,4,2 which is not right
by removing 2, it becomes 1,4,10,4
Stephen James
@sjames1958gm
Jun 28 2018 15:23
Then try test 14, which has 4 then 6
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 15:23
There are two reasons.
Oops. You're right.
It doesn't have to differ by 1.
Awww...which means that my code is...wrong.
Stephen James
@sjames1958gm
Jun 28 2018 15:25
Rather than compare the difference to 1 or -1 just use > or <
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 15:25
Yeah, I changed it to <= -1
It still doesn't work. The difference is that from 8 tests, it increased to 9 tests correct.
Stephen James
@sjames1958gm
Jun 28 2018 15:28
step by step :)
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 15:29
I do step by step for 3 hours.
I don't know if my whole logic is wrong in this situation or it's just that it needs some tweaks.
Stephen James
@sjames1958gm
Jun 28 2018 15:39
Which is the one that failed?
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 15:40
I have so many of my code variants lol
do you want the current one?
Stephen James
@sjames1958gm
Jun 28 2018 15:41
@OGTechnoBoy Which test case fails?
My challenge with this one was that you could remove either none, or either one of two if they were out of order.
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 15:43
Well, let's see
Test 2
Test 5
Test 10
Test 11
Test 14
Test 15
Test 16
Test 17
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 15:53
My problem is that I want to find which one loop was correct.
Did you find the issue?
Nate Mallison
@NJM8
Jun 28 2018 15:59
Anything wrong here?
router
  .route('/checkOut')
  .post((req, res, next) => {
    db.Bars.findOneAndUpdate({
      barId: req.body.barId
    }, {
      $pull: {
        peopleHere: req.body.peopleHere
      }
    }).then(doc => {
      res.send('removed')
    }).catch(error => {
      res.send(error)
      return next(error)
    })
  })
I'm not getting any errors but it isn't removing the data
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 15:59
What's that?
Jason Luboff
@JLuboff
Jun 28 2018 15:59
@NJM8 barId is the mongo ID?
Nate Mallison
@NJM8
Jun 28 2018 16:00
nope
id from yelp
Mongoose: bars.findAndModify({ barId: 'h0nPGPVrqZHCrrauTrywrA' }, [], { '$setOnInsert': { createdAt: new Date("Thu, 28 Jun 2018 15:56:31 GMT") }, '$set': { updatedAt: new Date("Thu, 28 Jun 2018 15:56:31 GMT") }, '$pull': { peopleHere: 'nate' } }, { overwrite: undefined, new: false, upsert: false, fields: {} })
Jason Luboff
@JLuboff
Jun 28 2018 16:00
Got it.
Nate Mallison
@NJM8
Jun 28 2018 16:00
should upsert be true or something?
Jason Luboff
@JLuboff
Jun 28 2018 16:00
upsert should be true if you want a returned docum,ent
Or that is, the updated document
You've verifed that req.body.barId exists?
Nate Mallison
@NJM8
Jun 28 2018 16:04
oh
sending the wrong id
ahh, thought I was sending the right id but I sent the check out id after setting the new one in the front end. tricky tricky
Nate Mallison
@NJM8
Jun 28 2018 16:10
@OGTechnoBoy That's Mongoose, ORM for MongoDB.
Jason Luboff
@JLuboff
Jun 28 2018 16:15
:+1:
Nate Mallison
@NJM8
Jun 28 2018 16:25
@JLuboff Can I set the result of a DB search to a variable?
when I do my yelp search I go through and add a peopleHere array to each result, then I want to do a db.Bars look up to see if each bar has someone there and pop them into the peopleHere array.
so can I do bar.peopleHere = db.Bars.find(bar).then(res => return res.peopleHere)
that's shorthand
Jason Luboff
@JLuboff
Jun 28 2018 16:28
Mmmm
Try it, not sure never done it lol
Nate Mallison
@NJM8
Jun 28 2018 16:28
oh, haha
Christopher McCormack
@cmccormack
Jun 28 2018 16:28
is bar just an object you're sending back to your frontend?
you'd have to use async await for that syntax I think
Nate Mallison
@NJM8
Jun 28 2018 16:29
yes
that's what I was thinking too, operations being async
Christopher McCormack
@cmccormack
Jun 28 2018 16:30
using mongoose though
Nate Mallison
@NJM8
Jun 28 2018 16:32
nice, I never thought of using await that way, but makes sense, just throw it in front of an async operation
Christopher McCormack
@cmccormack
Jun 28 2018 16:33
async await makes db operations SOO much easier
combine it with using mongoose instance/static methods you can make some much cleaner code
Jason Luboff
@JLuboff
Jun 28 2018 16:36
My code so clean you can eat off it
alpox
@alpox
Jun 28 2018 16:36
@cmccormack The bad thing is that if an error happens, the error is not handled unless you add try/catch everywhere in the routes ;)
Christopher McCormack
@cmccormack
Jun 28 2018 16:37
@alpox yup :)
Nate Mallison
@NJM8
Jun 28 2018 16:37
or define your own function to handle each async call with a try catch in it
yeah?
Christopher McCormack
@cmccormack
Jun 28 2018 16:38
One try catch is still nicer than tons of nested callbacks
Nate Mallison
@NJM8
Jun 28 2018 16:41
SyntaxError: await is only valid in async function
?
Christopher McCormack
@cmccormack
Jun 28 2018 16:42
wrap the callback, not the method
router.post("/updatedresults", async (req, res, next) => {
not
async router.post("/updatedresults", (req, res, next) => {
Nate Mallison
@NJM8
Jun 28 2018 16:43
no for db lookups
const thisBar = await db.Bars.findOne({ barId: business.id })
oh I see
I missed that in your code
Christopher McCormack
@cmccormack
Jun 28 2018 16:44
I've seen that error a bunch of times :)
Nate Mallison
@NJM8
Jun 28 2018 16:45
hmmm, I don't think this will work, I'll just do a find with a populate then mess with the data and send it
it's already inside the yelp callback so it doesn't like it
alpox
@alpox
Jun 28 2018 16:46
function middleware(fn) {
    return (req, res, next) => {
        fn(req, res, next).catch(err => {
            next(err);
        })
    }
}

....
.get(middleware(async (req, res) => {
        const posts = await Post.find({});

        res.json(posts);
    }))

....
function errorHandler(err, req, res, next) {
    if(err) {
        res.status(500).json({ error: "An error happened" });
    }
}

....
app.use(errorHandler);
May be an attempt shrug
Its more streight forward in koajs :D
Christopher McCormack
@cmccormack
Jun 28 2018 16:50
Yeah I have an error handler already and just use this in my try/catch:
   } catch(err) {
      return next(err)
    }
alpox
@alpox
Jun 28 2018 16:50
yea that leads to the same thing :D
Jason Luboff
@JLuboff
Jun 28 2018 16:53
but the question is...do you have an error handler for an uncaughtException?
Christopher McCormack
@cmccormack
Jun 28 2018 16:53
that's what the try catch does
Jason Luboff
@JLuboff
Jun 28 2018 16:54
So do you restart your sever then?
uncaughtException will crash the server
Christopher McCormack
@cmccormack
Jun 28 2018 16:54
no try catch catches that exception
so it's not uncaught
alpox
@alpox
Jun 28 2018 16:55
@JLuboff Nothing can crash there
Or not much :D
If there is a try/catch in every middleware
Jason Luboff
@JLuboff
Jun 28 2018 16:55
Ideally... ya, your code should never throw an uncaughtException lol
Christopher McCormack
@cmccormack
Jun 28 2018 16:56
right - if you're catching everything, no uncaught - it's a tautology!
Jason Luboff
@JLuboff
Jun 28 2018 16:58

A little...just in case I have

if (process.env.NODE_ENV === 'production') {
  process.on('uncaughtException', (err) => {
    console.error(err.stack);
    nodeMailer.uncaughtException(err);
  });
  sql.on('error', (err) => {
    console.error(err);
    nodeMailer.uncaughtException(err);
  });
}

Inside the mailer I have process.exit(1); so along with a process manager (pm2 in my case) the server will restart at least without any intervention

OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:05
So...can anyone help me?
I tried a lot different code variants.
Nothing worked.
Christopher McCormack
@cmccormack
Jun 28 2018 18:07
@OGTechnoBoy I got it to work within a single for loop if that helps
Nate Mallison
@NJM8
Jun 28 2018 18:08
what challenge?
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:08
@cmccormack Why my code doesn't work?
And do I need to change my whole logic or that it is fine as it is and I just need tweaks?
Christopher McCormack
@cmccormack
Jun 28 2018 18:09
@OGTechnoBoy I have no idea why your code doesn't work, I can't see it
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:10
``
function almostIncreasingSequence(sequence) { var bool; for(var i = 0; i < sequence.length-1; i++) { sequence.splice(i,1); if((sequence[i+1] - sequence[i]) >= -1) { bool = true; } else { bool = false; } } return bool === true; }
I think it doesn't work because bool will take the last splice loop's failure/or success, right?
Christopher McCormack
@cmccormack
Jun 28 2018 18:17
Can you paste that using the following markdown?
```
code
```
one line is hard to follow
@NJM8 almostIncreasingSequence on Codefights
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:18
```
function almostIncreasingSequence(sequence) {
   var bool;
   for(var i = 0; i < sequence.length-1; i++) {
      sequence.splice(i,1);
      if((sequence[i+1] - sequence[i]) <= -1) {
         bool = true;
         }
         else {
         bool = false;
         }
}
   return bool;
}
```
It only passes 8-9 tests.
I can't figure the problem
My theory is that bool takes the last operation which causes issues if the sequence was correct before the end.
Christopher McCormack
@cmccormack
Jun 28 2018 18:20
why <= -1?
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:20
Or that splice removes items which causes problems
Because of the difference.
Since the order is assending(from low to high)
Wait a min.
Christopher McCormack
@cmccormack
Jun 28 2018 18:21
splice does modify in place
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:21
I think I screwed stuff up in if condition.
Christopher McCormack
@cmccormack
Jun 28 2018 18:21
There are a few conditions you aren't accounting for as well
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:22
If the order is from low to high, and something like this happened: 1,2,3. Array[i+1] is 2 and array[i] is 1, which means 2-1 = 1 not -1
I screwed things up in if condition.
And yeah, splice does modify the array but I couldn't figure any other way to do it, maybe I try slice(0)?
Christopher McCormack
@cmccormack
Jun 28 2018 18:24
if you do comparisons around the current iteration value you shouldn't need splice or slice, just check differences
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:25
I need splice
Because it says that you need to remove an element from array for the array to be increasing.
Daniel Simeonov
@dbsimeonov
Jun 28 2018 18:26
Hi guys, I'm doing a codewars challenge, and it asks me to: should return as a plain English word in lower case the number of rolls he must buy. , is there a method or function that I'm not aware of, or should I just hardcode it inside array? ps. trasnfering the number to english word
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:26
So my logic was to try to remove every element from the loop and see if it is true or not.
Christopher McCormack
@cmccormack
Jun 28 2018 18:26
It says you need to determine if it is possible to obtain an increasing sequence, not that you need to return that sequence
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:26
I think you need .toLowerCase() method.
Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array.
See? it ask to see if removing an element causes the sequence to be increasing.
Christopher McCormack
@cmccormack
Jun 28 2018 18:27
@OGTechnoBoy I solved it without splice
If you want to use splice feel free, but it doesn't help to defend a method that so far has not worked for you
be open to trying different ways
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:29
You're right.
Maybe splice wasn't the right method to do it. My next algorithm is to check if every element has 1 or more difference from every previous element, if it found an element that has -1 or less then it will remove it and continue, if it found another element that has the same issue then it should return false.
Is it correct,
?
Christopher McCormack
@cmccormack
Jun 28 2018 18:30
You can remove it, but easier to just mark that you found one
then if you find another one, you know it should fail
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:31
Yeah but the problem is that it should look globally.
Christopher McCormack
@cmccormack
Jun 28 2018 18:31
should it?
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:31
Oh nevermind. I think that my algorithm is right.
Maybe. I don't even know if it is possible to do it.
Anyway, thank you for the help!
Christopher McCormack
@cmccormack
Jun 28 2018 18:32
np
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:40
function almostIncreasingSequence(sequence) {
   var counter = 0;
   for(var i = 0; i < sequence.length-1; i++) {
      if(sequence[i++] - sequence[i] >= 1) {
         continue;
      }
      else {
         counter += 1;
      }
   }
   if(counter > 1) {
      return false;
   }
   return true;
}
It only passes 10 tests.
I'm gonna give up on this challenge.
Christopher McCormack
@cmccormack
Jun 28 2018 18:41
@OGTechnoBoy don't increment i
i+1 not i++
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:42
Why?
Christopher McCormack
@cmccormack
Jun 28 2018 18:42
You should examine the tests that are failing and see why they are different than the ones that pass
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:42
Nice. It's now 14 tests.
I do that, believe me I do that.
I just don't know what the problem
Christopher McCormack
@cmccormack
Jun 28 2018 18:43
i++ means you will increment i after accessing sequence[i]
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:43
Ah. Thank you for that!
Christopher McCormack
@cmccormack
Jun 28 2018 18:44
Your method isn't taking into account WHICH value should be removed to be successful, so you may be incrementing your counter twice even if removing a different value means it would return true
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:50
What do you mean?
I'm sorry but I didn't understand what do you mean.
My code finds if the next value is decreasing or increasing.
If found it increasing then it will continue to the next value, if found it decreasing then it will increase counter by 1, then at the end, it sees if counter >= 2 or not(which means if there are 2 decreasing values or not) so it returns true or false based on the result and value of counter.
Christopher McCormack
@cmccormack
Jun 28 2018 18:55
but you aren't taking into account which number should actually be removed, should it be the current value or the next value
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:55
Yes but I didn't remove anything.
Christopher McCormack
@cmccormack
Jun 28 2018 18:56
[ 1, 3, 4, 3, 5 ] Should I remove 4 or 3?
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:56
I didn't even use splice(as you told me)
Christopher McCormack
@cmccormack
Jun 28 2018 18:56
just pretend you remove it
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:56
Neither. Because at both situations, counter will equal 2 or more which will return false.
Christopher McCormack
@cmccormack
Jun 28 2018 18:56
will it?
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:56
Yes.
Christopher McCormack
@cmccormack
Jun 28 2018 18:57
so then your code will fail on a test that should return true
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 18:57
Oops. I forgot that the difference doesn't have to be always 1
Sorry for that. Yeah it should return true.
I don't understand your point. My code works at that situation and returns true.
Christopher McCormack
@cmccormack
Jun 28 2018 19:00
which are failing?
I gave one scenario but there are a few to account for, failing tests should lead you to adding the conditions necessary
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 19:05
[1, 2, 1, 2] this one fails.
Because it increases from 1 to 2 then goes down to 1, so counter becomes 1
Then it increases again to 2
It returns true(it supposed to return false) because I didn't remove 1
But when I tried to remove 1 by splice, the code goes wrong.
I'm sorry but I'm awful at coding
Christopher McCormack
@cmccormack
Jun 28 2018 19:07
simulate removing the item by adding conditionals that check AROUND that value
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 19:08
I could do that but is there another method?
Jason Luboff
@JLuboff
Jun 28 2018 19:08
Meeting Title: Project Final Review
Results: Ya we'd like these additional features added
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 19:08
I don't want to do many if conditions, it's like bad coding because you can't get "over" the problem you face
Christopher McCormack
@cmccormack
Jun 28 2018 19:09
@OGTechnoBoy I hear you, but it may be a lot easier to get it working first, THEN figure out where you can simplify
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 19:09
Good advice. I will try that.
Thank you for helping!
Christopher McCormack
@cmccormack
Jun 28 2018 19:11
@OGTechnoBoy I'm right there with you though, I hate adding ANY conditional statements if possible ( I like ternary or simple logic operators) but these exercises tend to lean on conditionals more as they aren't very similar to real world scenarios
Jason Luboff
@JLuboff
Jun 28 2018 19:15
@cmccormack ternary :heart:
Christopher McCormack
@cmccormack
Jun 28 2018 19:16
@JLuboff working with react, you never feel like adding statements as they make the code less functional, ternarys and maps are everywhere
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 19:40
I'm gonna be mad.
I'm freaking trying every if condition
every if condition possible
Christopher McCormack
@cmccormack
Jun 28 2018 19:40
@JLuboff how many new features
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 19:40
smaller than 0
bigger than 0
smaller than 1
bigger than 1
What is in the heck is the right if condition!!!!!
Christopher McCormack
@cmccormack
Jun 28 2018 19:42
There isn't a single if condition that will capture everything you need to check, not without lots of && and || at least
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 19:42
More if conditions?
That is a nightmare.
That's it. I'm gonna give up and see the answer.
Adding more if conditions means that I'm not qualified to solve this challenge.
Jason Luboff
@JLuboff
Jun 28 2018 20:25
@cmccormack Eh.. just a couple. Requires adding a few columns to one of my database tables and a few tidbits to the front/back ends to handle it. It'll only take me a day to get everything done.
Christopher McCormack
@cmccormack
Jun 28 2018 20:29
@JLuboff a weekend you mean :)
Jason Luboff
@JLuboff
Jun 28 2018 20:29
I don't work weekends :smile:
Christopher McCormack
@cmccormack
Jun 28 2018 20:30
meaning you will be forced to do it over the weekend
Jason Luboff
@JLuboff
Jun 28 2018 20:30
I guess if they want to pay double time
But nah..I'll probably have everything done including the server within a week or two... they won't be ready to have a meeting about it (with all those involved) until August it sounds like lol
Joseph
@revisualize
Jun 28 2018 20:31
HEY.
Hey*
Caps lock was on. :P
Jason Luboff
@JLuboff
Jun 28 2018 20:31
HEY
Joseph
@revisualize
Jun 28 2018 20:33
So, I got this Network Support Engineer role. I've been here since Monday. They didn't have a computer for me. They don't have a phone for me.
They're a Managed Services Provider and in the last 4 days they've lost two clients.
Jason Luboff
@JLuboff
Jun 28 2018 20:33
Lol.. so...you've just been hanging out?
Joseph
@revisualize
Jun 28 2018 20:34
The computer that they TRIED to give me was a customer scrap that they didn't want repaired and one of the techs "repaired" it.
If this counter offer pushes through.. I'm jumping ship.
I don't understand how a company can know that I'm on-boarding as a Network Support Engineer and give me a previous customer's trash.
Jason Luboff
@JLuboff
Jun 28 2018 20:38
It happens but if they had advanced notice, they should have had something
Joseph
@revisualize
Jun 28 2018 20:39
Over two weeks.
Jason Luboff
@JLuboff
Jun 28 2018 20:40
Eh...ya that aint great
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 20:41
Please please just the last hints.
2 tests to go
function almostIncreasingSequence(sequence) 
{ 
var counter = 0; 
for(var i = 0; i < sequence.length; i++) { 
        if(sequence[i+1] - sequence[i] <= 0 || sequence[i-1] - sequence[i+1] === 0) {
        counter += 1;
        }
} 
 return counter === 1;
}
I need the last hints, please.
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 20:47
Help?
Christopher McCormack
@cmccormack
Jun 28 2018 21:14
@OGTechnoBoy which tests are failing?
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 21:15
I dont remember this exercise but do you need to know how many times you would need to increase stuff to get an incresing sequence?
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:15
I updated the code
this is the updated code which passes 15 test and there are only 2 remaining
function almostIncreasingSequence(sequence)  {
var counter = 0; 
for(var i = 0; i < sequence.length+1; i++) { 
        if(sequence[i] - sequence[i-1] <= 0 || sequence[i+1] - sequence[i-1] < 0) {
        counter += 1;
        }
} 
 return counter === 1;
}
the failed tests are test 3 and test 17
Christopher McCormack
@cmccormack
Jun 28 2018 21:17
@tiagocorreiaalmeida you have to be able to remove a single item from an array and that array should then contain only increasing values. how much they increase doesn't matter provided it is more than 0
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:17
Note: When I add else if with the same condition as ||, test 3 gets passed but instead, test 14 doesn't get passed
Christopher McCormack
@cmccormack
Jun 28 2018 21:17
@OGTechnoBoy can you provide the actual test arrays that are failing?
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:18
When I change it to <= 0, test 3 also gets passed and test 14 doesn't get passed
Okay:
Test 3: [1, 2, 1, 2]
Christopher McCormack
@cmccormack
Jun 28 2018 21:18
@OGTechnoBoy if you're going to test i-1 you should start your for loop at 1 not 0
similar for your sequence.length in the conditional, should be -1 not +1
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:19
And test 17: [3, 5, 67, 98, 3]
I tried -1
The result was that only 11 test got passed.
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 21:19
can you just send me the link? I think you are complicating it
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:20
So I changed it to only .length without adding or minus
Christopher McCormack
@cmccormack
Jun 28 2018 21:20
@OGTechnoBoy it doesn't matter how many tests pass, it matters why the tests didn't pass
you should be looking at the tests that don't pass and examining why that is the case, what you need to actually adjust
walk through it on paper or in your head before you change any code
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:20
I do that.
I do that since 8AM
Now I just don't care.
However, interesting enough, when changing it to -1, test 14 and test 17 gets passed
Like, take this one
[1, 3, 2, 1]
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 21:23
well the basic part you already got it if the next number is equal or less than the rpevious you increase the count, but if the next number is less or equal to the curent one and the one after it so it would be i +2is also less or equal to it you can return false
that'sone way of doing it
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:24
What I don't understand.
Why the heck when I change < to <=, everything changes
and when I change || to else if everything changes.
What is the kind of this challenge.
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 21:25
go by steps really
one if to check if the current value is smaller or equal to the previous one
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:25
Guess what, I'm from 8AM trying to solve it.
I'm sorry but I can't take it anymore.
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 21:25
well dont pressure your self too much
Diego Mayer
@Chrono79
Jun 28 2018 21:26
@OGTechnoBoy Go do something else, maybe the inspiration will come then
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 21:26
I remember once I got started on codefights I could barely do one of the challengs and I used to watch them on youtube to understand it, almost one year later I deleted everything, and took it almost unthil the end of it tbh
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:27
It is the night
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 21:27
@OGTechnoBoy https://www.youtube.com/watch?v=smuKknnNZ3w watch it with attention and avoid always see the solution before really giving your best at it
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:27
It's 10:27PM
I can't do something else
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 21:27
@Chrono79 I got here a funny one wanan give it a look ?:D
Diego Mayer
@Chrono79
Jun 28 2018 21:28
Watching tv, reading a book, listening some music?
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:28
And it seems that my programming brain just can't take it at its current state. I cleaned my room, I brought stuff, I went out with my friends/family...etc
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 21:28
one of the fews I really haven't done, https://codefights.com/arcade/intro/level-12/uRWu6K8E7uLi3Qtvx look at it
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:28
But the inspiration hasn't come.
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 21:28
@OGTechnoBoy watch the video and dont expect to learn all in one day
he will walk you trough it
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:29
Can you just give me 1 hint?
1 last hint why the code doesn't work correctly?
Maybe I will solve it finally.
Diego Mayer
@Chrono79
Jun 28 2018 21:30
@tiagocorreiaalmeida I'll check it later, I didn't like about CF that it has a clock, I feel like I'm in a Saw movie :P
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 21:30
you can unlock it for 300coints tough eheh
oh a clock nm
readed lock
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:30
That is a horrible way to learn.
You won't learn anything by doing that.
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 21:30
the arcade mode has no clock @Chrono79
Diego Mayer
@Chrono79
Jun 28 2018 21:31
Then I'm gonna check it at home :+1:
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:31
I will leave it for Tomorrow
If I don't fix it next day. I will get my hands dirty and look at some solutions.
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 21:32
look at some of the tests thats failing try to look at the array and go trough it like your code is doing
and see why its failing
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:32
I did that.
The problem is when I fix something, something else gets wrong.
I mean, I know the fix of test 14 and test 3
But when I fix 14, 3 gets wrong
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 21:33
you need one for all of them
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:33
When I fix 3, 14 gets wrong
When I fix 17, most of the tests get wrong
I didn't figure the right pattern.
I don't know, maybe because I'm over tired of testing and editing this code over and over almost all the day.
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 21:34
well there's a reason for that, maybe you will have to refactor some of the code, I dont know what more can I tell you, like I told you I watched the video above back then, cause he wont jump straight to the solution he will explain you the way he tought about it
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:35
But I don't want him to solve it. I want to solve it myself.
Unless I give up(which is likely) then I will go watch the video
Btw, which level you are in?
OGTechnoBoy
@OGTechnoBoy
Jun 28 2018 21:40
Bye
Tom
@moT01
Jun 28 2018 21:47
whats my problem with this challenge? https://learn.freecodecamp.org/coding-interview-prep/project-euler/problem-2-even-fibonacci-numbers
function fiboEvenSum(number) {
  let total = 0,
    last = 1,
    current = 2,
    next,
    terms = 0;

  while(terms <= number) {
    if(current % 2 === 0) {
      total += current;
    }

    next = last + current;
    last = current;
    current = next;
    terms++;
  }

  return total;
}
scratch that - < instead of <= in my while test made it work
Christopher McCormack
@cmccormack
Jun 28 2018 22:01
@Chrono79 did you just complete isLucky?
:D
Diego Mayer
@Chrono79
Jun 28 2018 22:02
@cmccormack yes ;)
Far from the level @tiagocorreiaalmeida mentioned
But I'll see what I can do to reach that far, knowing there is no clock I'll take my time
Christopher McCormack
@cmccormack
Jun 28 2018 22:03
image.png
Diego Mayer
@Chrono79
Jun 28 2018 22:04
I won! XD
Christopher McCormack
@cmccormack
Jun 28 2018 22:05
Well I voted you up so you're probably way above me now
Diego Mayer
@Chrono79
Jun 28 2018 22:05
Thanks, I'll check that voting thing later
Christopher McCormack
@cmccormack
Jun 28 2018 22:07
You're 28 now
Diego Mayer
@Chrono79
Jun 28 2018 22:08
Now I'm walking home, see ya :wave:
Jason Luboff
@JLuboff
Jun 28 2018 22:09
@Chrono79 Hi, bye
Christopher McCormack
@cmccormack
Jun 28 2018 22:09
@Chrono79 later
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 22:20
@Chrono79 you can unlock part's of the levels with coins, either way that exercise just seems like too much math for me :D
Jason Luboff
@JLuboff
Jun 28 2018 22:21
@tiagocorreiaalmeida Don't you let @Masd925 or @Blauelf hear you say that
Tiago Correia
@tiagocorreiaalmeida
Jun 28 2018 22:42
:smile:
Markus Kiili
@Masd925
Jun 28 2018 23:23
:imp: