Codesmith Pride Alumni Panel
38:38
Пікірлер
@ULTIMARAGNAR0K
@ULTIMARAGNAR0K 2 күн бұрын
Or you could just code in C and actually learn why you are doing things…
@kelvinxg6754
@kelvinxg6754 3 күн бұрын
Thid problem exclusive to JS.
@ericdimarzio5756
@ericdimarzio5756 6 күн бұрын
Thanks to the instructor!
@ericdimarzio5756
@ericdimarzio5756 7 күн бұрын
Just completed this assignment and am getting "X - expected '22' to equal 4" in the problem checking interface. I was puzzled by this because my output is the exact expected output and doesn't say 22 anywhere. I came her to check and....I have the exact same code as the solution given here. Anyone else getting this? Seems like a bug.
@ericdimarzio5756
@ericdimarzio5756 8 күн бұрын
Love seeing how the increment operator doesn't update the index variable until after the 'result' has been updated. Really cool insight into how JS handles tasks. Thank you!
@xazax91
@xazax91 8 күн бұрын
And then cry that JS is slow. If you work with that huge data sets, write your own "low level" plain-old-for-loop algorithm for such trivial things instead of wasting cpu time for "fancy functional code".
@nickandrievsky5705
@nickandrievsky5705 9 күн бұрын
Is creating a problem out of nothing is a blessing, curse or skill?
@weareloved
@weareloved 12 күн бұрын
🫶🏼
@imaginarystranger1974
@imaginarystranger1974 14 күн бұрын
Why would anyone ever try to work with big data in JavaScript? It's used to implement logic and certain functionality for front-end, not back-end.
@yy-pv7bc
@yy-pv7bc 16 күн бұрын
0:01
@mahmoudwalid1703
@mahmoudwalid1703 18 күн бұрын
No, The best way is use $max that in mongoDB⭐😀 reduce with large array takes much of memory
@vahan6500
@vahan6500 18 күн бұрын
These people should not be come close to computers …
@NoNameNoShame22
@NoNameNoShame22 18 күн бұрын
Why oh why are simple for-loops so hated?
@nnanna0013
@nnanna0013 19 күн бұрын
L language
@Detective_Jones
@Detective_Jones 20 күн бұрын
Thank you! Keep it going KZbin recommends!!
@PatatorSupelec
@PatatorSupelec 21 күн бұрын
Why can't the JS max function just take an array as parameter...
@MuhammadAhmed-pd8zu
@MuhammadAhmed-pd8zu 24 күн бұрын
In all honesty, when it comes to learning and sharing expertise, there isn’t need to tag, cite someone else’s content to show it wasn’t comprehensive and then show that you cracked the code of the thing, and let me show how its done. Just a personal opinion. But thank you, something new to me and JavaScript full of these swags anyways.
@ahmedrakan1789
@ahmedrakan1789 25 күн бұрын
There is problem with your code too, if we passed empty array, it will throw type error, always use initial variable with reduce, in this case -inf
@eantropix
@eantropix 25 күн бұрын
How are you defining the accumulator and the current element? Just a and b? That feels extremely confusing...
@ebryan7578
@ebryan7578 25 күн бұрын
'Promosm'
@alpachino468
@alpachino468 28 күн бұрын
I use Microsoft Paint as my IDE
@nomad4076
@nomad4076 29 күн бұрын
You are going to make me cry with the end 😭😭😭
@nomad4076
@nomad4076 29 күн бұрын
Do u have the source code?
@mirandajaramillo563
@mirandajaramillo563 29 күн бұрын
Wow this is so nice! I want to learn CSS
@Codesmith
@Codesmith 29 күн бұрын
What would you like to see in the tutorial?
@warguy6474
@warguy6474 Ай бұрын
js programmers try to write real code (impossible)
@kyaki101
@kyaki101 Ай бұрын
JavaScript developers will do everything but write code that doesn’t only rely on libraries
@Poylol
@Poylol Ай бұрын
Not a library, built-in js
@kyaki101
@kyaki101 Ай бұрын
@@Poylol i don't think you know what a library is, just because it's imported automatically doesn't mean it isn't a library
@Poylol
@Poylol Ай бұрын
@kyaki101 my bad I did not know if you were referring to the Math library, which yes, is a library; or the reduce method, which is a pure feature of js
@kyaki101
@kyaki101 Ай бұрын
@@Poylol no no, I mean that even if there isn’t a prefix like Math.something, doesn’t mean it’s no a library, like if you do fetch in js, you’re still using a library
@Poylol
@Poylol Ай бұрын
@kyaki101 from my understanding, the prototype methods are part of es6 and other past versions and as equally as other features like promises and classes they are features of the language. But I may be wrong and if I am TIL something new
@Solid_Fuel
@Solid_Fuel Ай бұрын
Im stupid, so i ask. How does the overhead of the reduce function compare to normal for loops and for each loops? Is there a sizable diffrence? Also, does the content matter? Like comparing numbers vs comparing objects with numbers?
@oziousmegasus9201
@oziousmegasus9201 26 күн бұрын
build-in function is mostly better than plain code in languages like js, python.
@Lord_zeel
@Lord_zeel 20 күн бұрын
The reduce function has been shown to be less performant than other loops such as Array.forEach, and standard for. Generally if performance is a big key, it should be avoided. It's actually pretty rare (arguably non-existent) for Array.reduce to be the best solution.
@hashtag9990
@hashtag9990 Ай бұрын
I like to use just arr.reduce(Math.max), nothing different, just looks more cleaner, but you can never be sure what js does
@hashtag9990
@hashtag9990 Ай бұрын
Does that mean js calls the function recursively? For all spread operated functions. Or probably just simple functions like max and min? Or it's just weird to think about they put all elements on stack, I thought it just creates another iterator or array internally. Even ts can't save you from these things, now I remember this video, everytime I use spread operator.
@florianw7600
@florianw7600 11 күн бұрын
No. It tries to pass 999999 arguments to a function. But passing so many arguments is simply not supported in JS (i.e. even if you wrote something like myFunc(1, 2, 3, <imagine rest of arguments here>, 999997, 999998, 999999) it wouldn't work)
@RazorMureithi
@RazorMureithi Ай бұрын
Original video please
@AminulIslam-hr9ki
@AminulIslam-hr9ki Ай бұрын
@m____77777
@m____77777 Ай бұрын
Your code works only if the maximum is a positive number. In case the maximum can be negative, reduce must be initialised with negative infinity 🙂‍↔️
@me-low-key
@me-low-key Ай бұрын
Is initializing with first element good as well?
@Kenny.S
@Kenny.S 27 күн бұрын
What are you talking about? It's simply going down the list and taking the max of the current max and the next head of the list. The first number when compared against the second create the accumulator so if you have negatives only there then it'll pick the least negative to start.
@jacksonkohls820
@jacksonkohls820 24 күн бұрын
@@me-low-keynot if the list is empty
@zxopink
@zxopink Ай бұрын
arr.reduce(math.max) No need to make a lambda function wrapper
@michaelthornes
@michaelthornes 5 күн бұрын
I can tell you didn't try it out. that's equivalent to: arr.reduce((accumulator, current, index, array) => Math.max(accumulator, current, index, array)) and it doesn't work
@99MrX99
@99MrX99 Ай бұрын
Why is there no math.max that takes an array?
@thatosello1021
@thatosello1021 Ай бұрын
What happened to sorting and popping?
@deadchannel8431
@deadchannel8431 25 күн бұрын
It slower :( unless you have this O(n) sorting algorithm that I made but will never show anyone because I’m planning to sell it Google, for millions.
@thatosello1021
@thatosello1021 24 күн бұрын
@@deadchannel8431 you are right. In my defence, performance was not an object lol
@666Leosch
@666Leosch Ай бұрын
It's obviously bad to turn entries of a data array into function arguments. I don't know the inner workings of JS-engines, but if the calling conventions are in any way similar to the C calling convention then you can only pass a small number of arguments through registers and most will be copied to the stack frame of the caller. You'll introduce an additional copy of the data unecessarily, you'll mess up the stack and worsen your cache hit rates
@AndrewARitz
@AndrewARitz Ай бұрын
the biggest mistake was using javascript
@SahilP2648
@SahilP2648 Ай бұрын
If that's what spread operator interactions are doing (creating recursions in library functions) then I understand why my browser is taking up 18GB memory. This is proper BS. Recursion should be your last alternative, not your first solution. The fact that this video is even made shows most JS developers don't even know what they are doing.
@kovacsemod
@kovacsemod Ай бұрын
It's probably because Math.max recurses and that's what's causing the error, not spreading the array. If that was the issue you could just use Function.prototype.apply to pass an array as arguments. Since you're only comparing two numbers in your implementation, it would yield better performance if you just compared them a > b instead of calling Math.max.
@AndrewARitz
@AndrewARitz Ай бұрын
What makes you think that a max function would need to be recursive?
@StarnikBayley
@StarnikBayley Ай бұрын
if reduce is being used, why not just use ternary operator (a>b?a:b) instead of Math.max to save one function call to Math.max on every iteration of reduce?
@sepdronseptadron
@sepdronseptadron Ай бұрын
Does a function call really have that much of an effect on the performance? converting it into a for loop probably have more of an effect than that also instead of doing .reduce((a, b) => Math.max(a, b)), just (edit: below doesn't actually work, nvm) doing .reduce(Math.max) also removes a function call (I think) and is more readable
@StarnikBayley
@StarnikBayley Ай бұрын
@@sepdronseptadron The interpreter needs to do 'more' work for a function call than a simple branching statement. The interpreter will have to execute more instruction just to setup the function call than to compare two variables as in ternary operator. However with modern CPU which can execute instructions with clock cycles in GHz range, as you said, I guess it does not really have much effect. However I ran a benchmark with 100 million integer array. The results are Math.max: 1.033s ternary: 838.819ms In terms of absolute time its meaningless, but in terms of time percentage, calling Math.max is 23% slower than ternary operator.
@sepdronseptadron
@sepdronseptadron Ай бұрын
@@StarnikBayley oh dam, didn't know it was as much as 20% also have you tried a normal for loop and what about using TypedArray? I'll benchmark and update
@StarnikBayley
@StarnikBayley Ай бұрын
@@sepdronseptadron there you go Math.max: 1.050s ternary: 840.984ms classic for loop:ternary: 172.282ms classic for loop:Math.max: 227.239ms In a classic for loop, where all the overhead of array.prototype methods are eliminated, Math.max is 30% slower than ternary operator. Yeah, in theory typed array may be faster but when JS engines like v8 are heavily optimized, I am not quite sure. I am not seeing any performance improvement with Int32Array for this particular scenario.
@sepdronseptadron
@sepdronseptadron Ай бұрын
@@StarnikBayley Got about the same results what surprised me a through is that for of is about the same speed as reduce I wanna do a bit more tests and see which one's faster I wanna try if using multiple "accumulators" will make a difference
@KadekRegen
@KadekRegen Ай бұрын
I will stick with traditional for loop. It works well in every languages.
@DeathSugar
@DeathSugar Ай бұрын
coulda just math max as param instead of arrowing it
@Badrsh-tk4cd
@Badrsh-tk4cd Ай бұрын
list.max??
@kirillbezrodny5107
@kirillbezrodny5107 Ай бұрын
Don't listen this guy plz. It's impossible to read in production. Write Math.max() , until it works, only then something others with comment.
@Chronologist89
@Chronologist89 Ай бұрын
Sometimes I feel like the last person who likes verbose syntax :D Like, I don't see anything wrong with just looping over the array and getting the largest element. Most languges optimize loops under the hood anyways. Obviously, getting a max is a rather trivial example, but still, is this convoluted syntax really necessary?
@82TheKnocKY
@82TheKnocKY Ай бұрын
If you have an array that big you really should be using a simple for loop as reduce will copy that array, leading to worse performance
@Seerinx
@Seerinx Ай бұрын
what? no it doesn't?
@mareau2193
@mareau2193 Ай бұрын
11 hour days? Kill me now.