These are chat archives for FreeCodeCamp/HelpJavaScript

21st
Jun 2018
Zebralight
@zebralight
Jun 21 2018 00:42
@bradtaniguchi gotcha
Kira
@codeymason
Jun 21 2018 03:58
How come in the lesson "Basic Javascript: Global Scope and Functions" the oopsGlobal variable returns undefined? I thought that the point was to display that a variable declared without var is automatically global, even when declared within a function...?
I'm not sure if this is normal, but I don't get any "test output" where it seems like it is supposed to go, so I had to test this in my own console. Is this the case for everyone?
abraham anak agung
@padunk
Jun 21 2018 04:04
@codeymason the if conditional said if (typeof oopsGlobal != "undefined") oopsGlobal is not undefined than print the output. you can check the output in your developer console (press F12)
Kira
@codeymason
Jun 21 2018 04:08
F12 doesn't work on my machine. When I access the console by R click -> inspect -> console, it doesn't seem to be responding to the code I edited for the exercise.
But rather the whole page....which makes sense. Is there a way to access the console for just the code I'm editing for the exercise?
abraham anak agung
@padunk
Jun 21 2018 04:10
@codeymason you can clear the console first (Ctrl + L) in windows and run your code in fcc (Ctrl + Enter). If you want a playground messing with your code, i suggets check https://repl.it
Kira
@codeymason
Jun 21 2018 04:15
@padunk for some reason I'm not able to get the code to run in my console on the page, but the link you sent me is working great. I'm getting => undefined which is strange.
abraham anak agung
@padunk
Jun 21 2018 04:16
@codeymason show your code or link to your code
Kira
@codeymason
Jun 21 2018 04:19

@padunk well, it's primarily FCC's code, but here it is. Passes the test, just trying to understand it better. ```// Declare your variable here
var myGlobal = 10;

function fun1() {
// Assign 5 to oopsGlobal Here
oopsGlobal = 5
}

// Only change code above this line
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}

whoops, sorry. formatting didn't work, but there it is. @padunk
abraham anak agung
@padunk
Jun 21 2018 04:20
@codeymason use triple ``` at start and end of your code in the new line
// Declare your variable here
var myGlobal = 10;

function fun1() {
// Assign 5 to oopsGlobal Here
oopsGlobal = 5
}

// Only change code above this line
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}
Kira
@codeymason
Jun 21 2018 04:21
@padunk so, i would expect both oopsGlobal and myGlobal to be defined. myGlobal because it was defined outside of any function, and oopsGlobal because it was declared within a different function, but without var, which I thought made it global.
abraham anak agung
@padunk
Jun 21 2018 04:21
oopsGolbal is a global var, cause you dont use var keyword
Kira
@codeymason
Jun 21 2018 04:22
@padunk when I pressed enter to go down a line and put in the last three backticks, I accidentally sent the message . I think I need to go into compose mode next time so enter doesn't send. sorry, new to this.
abraham anak agung
@padunk
Jun 21 2018 04:23
if oopsGlobal is undefined the ouput wont print its value
Kira
@codeymason
Jun 21 2018 04:23
@padunk right, that's what I thought. So why is the code returning undefined if both variables seem to be global, and therefore the output code should run for them, right?
abraham anak agung
@padunk
Jun 21 2018 04:24
the code use != which means is not undefined or if those var is global, than print its value
Kira
@codeymason
Jun 21 2018 04:26
@padunk And the var IS global. Both should be. So why is it returning undefined?
abraham anak agung
@padunk
Jun 21 2018 04:27
@codeymason did you output print out undefined?
Kira
@codeymason
Jun 21 2018 04:28
@padunk yes
Screen Shot 2018-06-21 at 12.28.30 AM.png
abraham anak agung
@padunk
Jun 21 2018 04:29
@codeymason that's weird, it should print myGlobal: 10 oopsGlobal: 5
Kira
@codeymason
Jun 21 2018 04:29
@padunk that's weird, right?
I thought so. Whew.
@padunk ok so I'm relieved to know I'm not wrong here.
abraham anak agung
@padunk
Jun 21 2018 04:30
@codeymason nah that one in your repl.it return undefined because you never call the function
Kira
@codeymason
Jun 21 2018 04:31
aha!
let me try that
abraham anak agung
@padunk
Jun 21 2018 04:31
add fun2() at the end
Kira
@codeymason
Jun 21 2018 04:32
Screen Shot 2018-06-21 at 12.31.44 AM.png
@padunk so that seemed to work for myGlobal, but not oopsGlobal.
abraham anak agung
@padunk
Jun 21 2018 04:36
@codeymason hmmm... idk bout this, maybe repl.it already use 'use strict'. btw your code is fine.
Kira
@codeymason
Jun 21 2018 04:37
@padunk ok cool. well thanks for helping me try to figure this out. i thought something was off, and i guess i was right.
abraham anak agung
@padunk
Jun 21 2018 04:38
@codeymason np. happy coding :smile:
Kira
@codeymason
Jun 21 2018 04:39
@padunk thanks! same to you.
mpmaan
@mpmaan
Jun 21 2018 06:56
This program prints undefined. I don't know what's wrong. Can anybody help?
function checkCashRegister(price, cash, cid) {
  let hash = {
    "PENNY": 0.01,
    "NICKEL": 0.05,
    "DIME": 0.1,
    "QUARTER": 0.25,
    "ONE": 1,
    "FIVE": 5,
    "TEN": 10,
    "TWENTY": 20,
    "ONE HUNDRED": 100
  }
console.log(available(hash, cid));
}
function available(hash,cid){
  return cid.reduce((prev, curr)=>{
    prev += hash[curr[0]]*curr[1];
  },0);
}
checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);
mpmaan
@mpmaan
Jun 21 2018 07:04
never mind..got it
Simon Cordova
@gbsimon87
Jun 21 2018 07:55
Hey all, good morning
Dhaval Vira
@dhavalveera
Jun 21 2018 07:56
hey
Simon Cordova
@gbsimon87
Jun 21 2018 07:58
Hey there - was wondering if anyone could lend a quick hand
I've got an input, image a pinpad, and upon entering a number, I only want to show the last digit, but the previous digits must be an asterisk - any thoughts how to accomplish such a task?
Blauelf
@Blauelf
Jun 21 2018 08:27
@gbsimon87 Something like this old jQuery plugin mentioned on css-tricks.com?
Simon Cordova
@gbsimon87
Jun 21 2018 08:27
Thank you @Blauelf , I will take a loog :)
look**
@Blauelf
Exactly like that, except can't use a plugin, need it in my React app
Blauelf
@Blauelf
Jun 21 2018 08:30
The article (of 2009) describes how he would build something like that. Maybe you can copy that.
Simon Cordova
@gbsimon87
Jun 21 2018 08:31
?
@Blauelf the same article on the link you sent me you mean
Blauelf
@Blauelf
Jun 21 2018 08:41
Is that component meant to just show the (partially masked) password? And if you want to mask the last character after a second or so, how does React work with asynchronous events? (like you typed a digit and then erased it, then typed another before the masking-timeout)
Simon Cordova
@gbsimon87
Jun 21 2018 08:44
The layout itself is an pinpad, so a disabled input up top and 9 numbers at the bottom. Upon clicking a button, it will take that button's value and insert it in the input. Currently it's working well just showing every number, I need to mask al but the last digit
Blauelf
@Blauelf
Jun 21 2018 08:48
You probably keep the number in a state. Couldn't you then just like .replace(/.(?!$)/g, "*") the input's value?
Simon Cordova
@gbsimon87
Jun 21 2018 08:55
That's probably what I'm looking for knowing you :)
Cheers buds I'll try that out
Blauelf
@Blauelf
Jun 21 2018 09:09
Somehow this regular expression looks just like random punctuation :P
mpmaan
@mpmaan
Jun 21 2018 09:09
(?!$) what does this do?
Blauelf
@Blauelf
Jun 21 2018 09:11
Negative look-ahead on string end.
This makes it not match on last character in the string.
Anabel
@AnabelSalomone
Jun 21 2018 09:12
Hey! Is anyone able to help with a question on FromArray (angular 5/6 )? :)
Blauelf
@Blauelf
Jun 21 2018 09:12
(?=) is positive look-ahead, (?!) negative look-ahead. $ has its regular meaning, string end.
mpmaan
@mpmaan
Jun 21 2018 09:13
:thumbsup:
Blauelf
@Blauelf
Jun 21 2018 09:14
Unlike non-capturing groups (?:), those don't consume characters.
Jose Pagan
@josepagan
Jun 21 2018 14:26
i found the tutorial on https://regexone.com/ very handy to learn about the topic
Jose Pagan
@josepagan
Jun 21 2018 14:33
stuck on the last challenge though, regex uses a part of my brain I havent used before!
Blauelf
@Blauelf
Jun 21 2018 14:36
What's the last one?
remove white space at the beginning and end of string
dont tell me the answer, I preffer to suffer every day
Blauelf
@Blauelf
Jun 21 2018 14:48
Isn't that complex. I see two ways to do it: Replacing the spaces around with empty strings, or matching the part between the spaces and use that one. There might be more, or ones that are more fun in some way or another.
Jose Pagan
@josepagan
Jun 21 2018 14:52
I know, thanks. Yesterday I got stuck in the simplex regex problem. It is not you it is me. :smile:
Blauelf
@Blauelf
Jun 21 2018 14:55
I just tried my second suggestion, and failed. But this new interface wouldn't tell me what my code actually does. Is there any way to geth the result of a console.log?
So no, it's not just you.
Oh, I'm so stupid. Non-greedy * is *?, not ?*.
Blauelf
@Blauelf
Jun 21 2018 15:03
That second method is same as suggested by https://regexone.com/problem/trimming_whitespace :D
Jason Luboff
@JLuboff
Jun 21 2018 15:06
:wave:
mpmaan
@mpmaan
Jun 21 2018 15:31
@Blauelf check browser console for your output of console.log()
sabahatullah
@sabahatullah
Jun 21 2018 15:44
how can I convert it a function

var firstDiv = $('.offers li:nth-child(1) .offer-header').height();
var secondDiv = $('.offers li:nth-child(2) .offer-header').height();

        if(firstDiv > secondDiv){
        console.log('first div longer');
        $('.offers li:nth-child(2) .offer-header').height(firstDiv);
        }else{
        console.log('second div longer');
        $('.offers li:nth-child(1) .offer-header').height(secondDiv);

}

basically I looking detect which header is bigger then getting the other header to match its height
Blauelf
@Blauelf
Jun 21 2018 15:45
@mpmaan I checked browser console, and nothing would show up. The new interface seems to work very differently from the old one.
sabahatullah
@sabahatullah
Jun 21 2018 15:46
That'll be great if I can have a function for more than two headers even
Blauelf
@Blauelf
Jun 21 2018 15:46
I used repl.it then.
mpmaan
@mpmaan
Jun 21 2018 15:46
which challenge? @Blauelf
mpmaan
@mpmaan
Jun 21 2018 15:47
i wrote console.log(2) and it got printed in my browser console
though it will only print after runnin the tests
Blauelf
@Blauelf
Jun 21 2018 15:49
@sabahatullah Why not store the heights in an array and use Array.max?
mpmaan
@mpmaan
Jun 21 2018 15:49
that is ok but this should work too
Blauelf
@Blauelf
Jun 21 2018 15:50
@mpmaan This time, it works. But last time, I also got console output from three sub-windows, now it's two.
Guess a page reload would have fixed the issue with the console.
mpmaan
@mpmaan
Jun 21 2018 15:50
which sub windows?
Blauelf
@Blauelf
Jun 21 2018 15:51

Now there are three, but doesn't change anything.

I guess there are iframes in the page, at least the console would show me three different documents which I can run code in.

mpmaan
@mpmaan
Jun 21 2018 15:52
@sabahatullah does your code print anything like first one is longer or the second one?
@Blauelf did you get the same output three times?
Blauelf
@Blauelf
Jun 21 2018 15:53
No, before I got no output, now I get one output like I would expect it.
Blauelf
@Blauelf
Jun 21 2018 16:14
Now I get what the three documents are. One main document with two iframes, one of which houses the code to be tested.
I don't get the second iframe, but having one for testing the code explains why it appeared only after running the tests. Still no idea why console.log wouldn't work before.
Brad
@bradtaniguchi
Jun 21 2018 17:01
Its time.... to wade back into legacy code
mpmaan
@mpmaan
Jun 21 2018 17:01
what is legacy code?
Brad
@bradtaniguchi
Jun 21 2018 17:02
Legacy usually means old, not up-to-date. So like VHS tapes are legacy hardware
Legacy code usually is old code that isn't maintained well, is outdated, and doesn't match with the "latest" code.
Jason Luboff
@JLuboff
Jun 21 2018 17:03
@bradtaniguchi I didn't know you knew what VHS were :P
Brad
@bradtaniguchi
Jun 21 2018 17:04
I'm not THAT young haha
Jason Luboff
@JLuboff
Jun 21 2018 17:05
Early 20's right?
Kudzu
@czhower
Jun 21 2018 17:05
8-Tracks.....
mpmaan
@mpmaan
Jun 21 2018 17:05
lol.. @bradtaniguchi what's vhs ?
Brad
@bradtaniguchi
Jun 21 2018 17:06
Yes, I had VHS when I was a kid. @mpmaan Fine, what about saying myspace is legacy software? hehe
Maybe thats not the best comparison
mpmaan
@mpmaan
Jun 21 2018 17:06
never heard of myspace as well
Brad
@bradtaniguchi
Jun 21 2018 17:06
Maybe a CD player is more like it
wow your pretty young I assume (or have never been exposed to that sorta stuff)
mpmaan
@mpmaan
Jun 21 2018 17:07
i got laptop and phone in mid 2016
Kudzu
@czhower
Jun 21 2018 17:08
Myspace was like Facebook kind of, and before it.
VHS are video tapes.
mpmaan
@mpmaan
Jun 21 2018 17:08
never had any experience with tech before that except for some computer labs in school
Jason Luboff
@JLuboff
Jun 21 2018 17:10
Thats something I take for granted..
Brad
@bradtaniguchi
Jun 21 2018 17:11
Yea I had a laptop since middle school, but didn't have a phone until the end of highschool
Jason Luboff
@JLuboff
Jun 21 2018 17:11
We had a family computer around when I was 5-6? I bought my first laptop end of 8th grade I think. First cell phone was late freshman or sophmore year cant remember
Really didn't need the cell phone but my parents were on the hook for it regardless so gave it to me
mpmaan
@mpmaan
Jun 21 2018 17:12
lol
i'm 20 @bradtaniguchi
Brad
@bradtaniguchi
Jun 21 2018 17:14
Im only 24 so I'm kinda right there still hehe
Kudzu
@czhower
Jun 21 2018 17:16
My first laptop had 640kb and 2 floppy drives :)
And was monochrome 640x480 screen.
Jason Luboff
@JLuboff
Jun 21 2018 17:17
@czhower Mine was a bit better than that :smile:
Kudzu
@czhower
Jun 21 2018 17:19
It had an optional 8087 math coprocessor that could do floating point math. :)
mpmaan
@mpmaan
Jun 21 2018 17:19
should i dive straight into react challenges or read some documentation first?
@czhower i studied 8087 last semester
Jason Luboff
@JLuboff
Jun 21 2018 17:20
My first laptop had windows xp, so gives you roughly an idea.. Pentium 3, 30 GB HD, 256 KB (upgraded to 512!)
Kudzu
@czhower
Jun 21 2018 17:29
@mpmaan Wow... intesting that they covered the 87
Blauelf
@Blauelf
Jun 21 2018 17:37
@czhower Was that first laptop one with an integrated trackball? I loved those. Don't fit in modern laptops, though, a few centimeters missing.
@JLuboff You probably meant 256 MB. Did that same memory upgrading stunt on my first laptop, a Pentium III-M of 800 MHz. But it was hard to find RAM the BIOS would accept. The chipset could not access memory chips over a certain size, so I had to search for rare modules with 16 chips. 20 GB HD (IBM TravelStar). Trusty old IBM. Sold to Hitachi. Now Western Disaster.
Kudzu
@czhower
Jun 21 2018 17:43
@Blauelf No.. this was before mice. :)
No trackball.. no pointer... ran DOS
I hated trackballs..I have really oily skin.. I wear the letters off keyboards and it was hell with trackballs... had to clearn them pretty much EVERY morning :(
Jason Luboff
@JLuboff
Jun 21 2018 17:44
@Blauelf Ya, that was a typo (more like my brain not processing right), it was MB. I happened to be working at a computer show so I was able to find it easily there.
Kudzu
@czhower
Jun 21 2018 17:44
Mine had 640kb,,, not MB... :)
Jason Luboff
@JLuboff
Jun 21 2018 17:44
I've never liked trackballs... always found them to be a pain to use
Kudzu
@czhower
Jun 21 2018 17:46
It was this or very similar... I dont think mine was Zenith but it was enarlyu same case as this...
Blauelf
@Blauelf
Jun 21 2018 17:47
@czhower You know, nobody needs more than 640kB of RAM. Bill Gates must know it, trust him. Also, that "Internet" thing is just a hype.
Jason Luboff
@JLuboff
Jun 21 2018 17:47
Too bad I don't remember the stats of our familys first home computer. Just know it was running Windows 3.11 and had a 3.5" floppy
Blauelf
@Blauelf
Jun 21 2018 17:49
@czhower That one's only slightly larger than the screen. The ones I knew had a small screen in the middle of the lid, with two sliders (brightness and contrast) next to them. And 640x400 pixels or so.
Or was it 640x200? Something like that.
Kudzu
@czhower
Jun 21 2018 17:49
Did gitter or this room disable image pastes and previews?
Jason Luboff
@JLuboff
Jun 21 2018 17:50
image.png
Nope
wel... thats a paste
but that worked
but maybe for links they did
Kudzu
@czhower
Jun 21 2018 17:50
hmm.. I cant paste images and no preview on links either.... gitter is buggy... guess its just another bug.
its always been futzy with image pastes.
Jason Luboff
@JLuboff
Jun 21 2018 17:50
You using the browser version or stand alone?
Kudzu
@czhower
Jun 21 2018 17:50
desktop
Jason Luboff
@JLuboff
Jun 21 2018 17:51
Ya same here
Wow... didn't know that up until SQL Server 2008...you couldn't insert multiple rows in one statement. That must have been horrible..
Blauelf
@Blauelf
Jun 21 2018 17:53
T-SQL? The one with function ISNULL, which is a pimped COALESCE? I always found that name confusing. I mean, "isnull" sounds like it should return a boolean.
Jason Luboff
@JLuboff
Jun 21 2018 17:53
ISNULL is a T-SQL only function, ya. I prefer COALESCE though
ISNULL only accepts two arguments, whereas COALESCE can have multiple.. not to mentioned coalesce is an ansi standard
But, they handle type precedence a bit differently (another reason I like coalesce better)
Blauelf
@Blauelf
Jun 21 2018 17:54
I thought the difference was more about the type. Like ISNULL guarantees the result to be of the type of the first argument.
It was something I never cared about.
Kudzu
@czhower
Jun 21 2018 17:55
@JLuboff Not really, you just issued multipel insert command (an extra word or two) and sent them in a batch.
As long as you did them in a tx, it wasnt a perf issue.
Jason Luboff
@JLuboff
Jun 21 2018 17:57
@Blauelf Correct, isnull will return the type of the first argument, which can then truncate the result and/or conversion issues. coalesce will use the type with highest precedence
@czhower I guess I'm lazy and don't want to have to keep typing Insert Into dbo.Table(col1, col2...) or copying and pasting that a bunch
Blauelf
@Blauelf
Jun 21 2018 17:57
I never used it with different types. So no conversion.
Jason Luboff
@JLuboff
Jun 21 2018 18:02
Example from my book I'm studying from
Declare @x as VARCHAR(3) = NULL, @y as VARCHAR(10) = '1234567890';
Select ISNULL(@x, @y) as ISNULLxy, COALESCE(@x, @y) as COALESCExy;

//Result
ISNULLxy = 123 //Use the first inputs type, thus truncates
COALESCExy = 1234567890 //Uses higher precedence
Brad
@bradtaniguchi
Jun 21 2018 18:52
Man, just spent like 3 hours fixing config issues due to people being lazy :/
each issue was litterally 1 character or one line,
Jason Luboff
@JLuboff
Jun 21 2018 18:54
How many configs were there
Brad
@bradtaniguchi
Jun 21 2018 18:54
  1. was a package.json issue, someone left in a ^ character on a package, so there was a version mistmatch between angular packages.
2.Was a gitignore issue, package-lock.json was in it, so my installations weren't "cached" or optimized so it took like 10 mins todownload packages
3.was a git issue where they removed package-lock and didn't add it back (due to the ignore issue), which also goes with 2 I guess
Jason Luboff
@JLuboff
Jun 21 2018 18:56
Well...if it makes you feel any better...I just realized I'm not going to be able to use my pagination query in production due to our SQL server being 2008 and Offset-Fetch wasn't introduced until 2012 :worried:
Brad
@bradtaniguchi
Jun 21 2018 18:56
time for a new query
Jason Luboff
@JLuboff
Jun 21 2018 18:57
Ya...just bummed since the query I have is beautiful! :joy:
Brad
@bradtaniguchi
Jun 21 2018 18:58
hahaha
I can FINALLY START WORKING -___-
Jason Luboff
@JLuboff
Jun 21 2018 19:07
Nice
anthonygallina1
@anthonygallina1
Jun 21 2018 20:52
:wave:
Brad
@bradtaniguchi
Jun 21 2018 20:53
:+1:
anthonygallina1
@anthonygallina1
Jun 21 2018 20:55
@JLuboff I like the way it can work with tables. I did some things in the Google challenge and was Like I dont know jquery and all the possibility
appending tables blew my mind
Jason Luboff
@JLuboff
Jun 21 2018 20:59
@anthonygallina1 With what can work with tables?
anthonygallina1
@anthonygallina1
Jun 21 2018 21:01
Jason Luboff
@JLuboff
Jun 21 2018 21:02
Still not 100% sure what we're talking about :smile:
anthonygallina1
@anthonygallina1
Jun 21 2018 21:03
@JLuboff I kept opening dev panel and looking up a writing direct. They kept directing to jquery. Kinda of a flip from here. I have a es6 ver of that writing direct to the dom and nodes
@JLuboff check code line 25
Tables
Jason Luboff
@JLuboff
Jun 21 2018 21:04
Oh, I was talking about SQL tables :smile:
anthonygallina1
@anthonygallina1
Jun 21 2018 21:05
@JLuboff JQuery works with sql tables 2?
Brad
@bradtaniguchi
Jun 21 2018 21:05
its that good
anthonygallina1
@anthonygallina1
Jun 21 2018 21:05
Learned something new Thank you @JLuboff
Jason Luboff
@JLuboff
Jun 21 2018 21:05
No, jQuery doesn't work with SQL tables
SQL requires a backend language to work with it
You can send the results of a SQL query (and thus a SQL table) to the front end in which jQuery can manipulate that
anthonygallina1
@anthonygallina1
Jun 21 2018 21:06
K going back to my corner and listening sorry :smile:
@JLuboff Interesting
Jason Luboff
@JLuboff
Jun 21 2018 21:07
Nothing to be sorry about :+1:
anthonygallina1
@anthonygallina1
Jun 21 2018 21:08
:smile:
koder3
@koder3
Jun 21 2018 21:42
Hey guys
Brad
@bradtaniguchi
Jun 21 2018 21:43
hello
koder3
@koder3
Jun 21 2018 21:48

For example using reduce I can subtract one value by another until a condition i cant explain it that well so let me give an example:

const arr = [65, 54, 34, 2, 1];
const arr1 = [98, 34, 23, 13, 2];
return arr.reduce((total, amount) => {
total = total - amount
return total
}, 0)

while doing all this i want to make sure the total - amount in the code above stops and returns total when arr1 is also being subtracted and its own total hits a specific value

so basically i want to use reduce on two arrays
is this possible or should i resort to a for loop?
Jason Luboff
@JLuboff
Jun 21 2018 21:53
You want two seperate total or one?
If one, then concat the two arrays and then reduce
return arr.concat(arr1).recuce(... (my syntax might be off)
koder3
@koder3
Jun 21 2018 21:53
two seperate
the arr should be dependent upon arr1 reduce subtraction hitting a specific value
Jason Luboff
@JLuboff
Jun 21 2018 21:54
If you want two seperate than you should put your reduce statement into a function
koder3
@koder3
Jun 21 2018 21:54
so can i access another reduce inside a reduce?
reduce function*
Jason Luboff
@JLuboff
Jun 21 2018 21:54
Maybe I'm not fully understanding
So you want it to stop when total is 13 for instance?
koder3
@koder3
Jun 21 2018 21:54
yes in arr1
the subtraction in arr1
and just return whatever the total is
i basically want two totals one for each array
and somehow i need to get them connected
Jason Luboff
@JLuboff
Jun 21 2018 21:56
I'm not really understanding what you're trying to achieve. Can you provide some psuedo-code?
koder3
@koder3
Jun 21 2018 21:58
im not exactly sure how to but lemme try
arr.reduce (total, amount){
if (total2   !==   x) {
total = total - arr
return total
}}
Total2 should also be a reduce function
Jason Luboff
@JLuboff
Jun 21 2018 21:59
psuedo-code is not actual code but written out code
First we check for this
Then we do this
koder3
@koder3
Jun 21 2018 22:00
yeah didnt join a university or attend any comp sci course yet haha sry
Jason Luboff
@JLuboff
Jun 21 2018 22:00
I mean I kind of get what you're trying to achieve, but I'm not sure reduce is the best tool for this
koder3
@koder3
Jun 21 2018 22:00
yeah ill try out the for loop
Jason Luboff
@JLuboff
Jun 21 2018 22:00
I think just using a regular loop might be better. But maybe @bradtaniguchi has a suggestion
koder3
@koder3
Jun 21 2018 22:00
this is for the cash register algorithm challenge by the way
Im somewhat close to success but getting the change is trickier then i assumed
But I feel its pretty possible
Anyways thanks @JLuboff
Brad
@bradtaniguchi
Jun 21 2018 22:03
My understanding is you want the total of two arrays right? With the second total DEPENDANT on the first total?
where the second only goes down to a certain amount, then stops subtracting I guess
koder3
@koder3
Jun 21 2018 22:03
the first dependent on the second
yeah
Brad
@bradtaniguchi
Jun 21 2018 22:04
the order of these two shouldn't matter at the end of the day haha
koder3
@koder3
Jun 21 2018 22:04
Yeah i guess so
is it possible with reduce
maybe i can use a function inside reduce
forEach?
Brad
@bradtaniguchi
Jun 21 2018 22:04
Well for the "first" guy, you can use reduce. But for the second you don't want to use reduce since there's no way to "skip" going thru the tiems
koder3
@koder3
Jun 21 2018 22:06
so a for loop for second?
Brad
@bradtaniguchi
Jun 21 2018 22:06
Yea, so you can use break; when your reach that point to stop going thru the loop
koder3
@koder3
Jun 21 2018 22:06
yeah thats a good idea
how do i connect both the totals
Brad
@bradtaniguchi
Jun 21 2018 22:06
You can't break out of a reduce/forEach, and dont want to waste iterations for no reason
idk what you mean, about connecting the two totals
koder3
@koder3
Jun 21 2018 22:07
nah forget that
Thanks
Ill work on it
Bye
:clap:
Jason Luboff
@JLuboff
Jun 21 2018 22:12
@bradtaniguchi Thanks for the assist
Brad
@bradtaniguchi
Jun 21 2018 22:13
np goodluck :D
@JLuboff anytime hehe
Jason Luboff
@JLuboff
Jun 21 2018 22:14
:+1:
Now to continue on to start testing SQL 2017...
Brad
@bradtaniguchi
Jun 21 2018 22:18
ew goodluck XD
Jason Luboff
@JLuboff
Jun 21 2018 22:18
Stupid VSC not seeing the server for some reason
Brad
@bradtaniguchi
Jun 21 2018 22:18
I thought you used Atom?
Jason Luboff
@JLuboff
Jun 21 2018 22:18
VS Community for C#
Brad
@bradtaniguchi
Jun 21 2018 22:19
Ah I see
Jason Luboff
@JLuboff
Jun 21 2018 22:19
(For working with C# that is)
VS Community for IDE, Atom for text editor :smile:
Brad
@bradtaniguchi
Jun 21 2018 22:20
Has anyone ever told you to use VSCode rather than Atom :P
Jason Luboff
@JLuboff
Jun 21 2018 22:20
Yup. You, @cmccormack uh...
Wierd...VSC isn't seeing either the current DB server or the Test DB server for adding a connection, but I can add the server and the previous connection I had to the current DB server is active
Jason Luboff
@JLuboff
Jun 21 2018 22:29
Huh. Got it by manually typing things.
Norvin Burrus
@ndburrus
Jun 21 2018 23:27
@AnabelSalomone this may be helpful :sparkles:
koder3
@koder3
Jun 21 2018 23:56
Hey guys if my code is ugly (as in uses too many loops, non-best practices, too many ifs)
but still solves the algorithm challenge is it fine?
I thought as a beginner it shouldnt matter because I can comeback and optimize it once im experienced or something