Or you could just code in C and actually learn why you are doing things…
@kelvinxg67543 күн бұрын
Thid problem exclusive to JS.
@ericdimarzio57566 күн бұрын
Thanks to the instructor!
@ericdimarzio57567 күн бұрын
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.
@ericdimarzio57568 күн бұрын
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!
@xazax918 күн бұрын
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".
@nickandrievsky57059 күн бұрын
Is creating a problem out of nothing is a blessing, curse or skill?
@weareloved12 күн бұрын
🫶🏼
@imaginarystranger197414 күн бұрын
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-pv7bc16 күн бұрын
0:01
@mahmoudwalid170318 күн бұрын
No, The best way is use $max that in mongoDB⭐😀 reduce with large array takes much of memory
@vahan650018 күн бұрын
These people should not be come close to computers …
@NoNameNoShame2218 күн бұрын
Why oh why are simple for-loops so hated?
@nnanna001319 күн бұрын
L language
@Detective_Jones20 күн бұрын
Thank you! Keep it going KZbin recommends!!
@PatatorSupelec21 күн бұрын
Why can't the JS max function just take an array as parameter...
@MuhammadAhmed-pd8zu24 күн бұрын
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.
@ahmedrakan178925 күн бұрын
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
@eantropix25 күн бұрын
How are you defining the accumulator and the current element? Just a and b? That feels extremely confusing...
@ebryan757825 күн бұрын
'Promosm'
@alpachino46828 күн бұрын
I use Microsoft Paint as my IDE
@nomad407629 күн бұрын
You are going to make me cry with the end 😭😭😭
@nomad407629 күн бұрын
Do u have the source code?
@mirandajaramillo56329 күн бұрын
Wow this is so nice! I want to learn CSS
@Codesmith29 күн бұрын
What would you like to see in the tutorial?
@warguy6474Ай бұрын
js programmers try to write real code (impossible)
@kyaki101Ай бұрын
JavaScript developers will do everything but write code that doesn’t only rely on libraries
@PoylolАй бұрын
Not a library, built-in js
@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Ай бұрын
@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Ай бұрын
@@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Ай бұрын
@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Ай бұрын
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?
@oziousmegasus920126 күн бұрын
build-in function is mostly better than plain code in languages like js, python.
@Lord_zeel20 күн бұрын
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Ай бұрын
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Ай бұрын
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.
@florianw760011 күн бұрын
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Ай бұрын
Original video please
@AminulIslam-hr9kiАй бұрын
❤
@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Ай бұрын
Is initializing with first element good as well?
@Kenny.S27 күн бұрын
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.
@jacksonkohls82024 күн бұрын
@@me-low-keynot if the list is empty
@zxopinkАй бұрын
arr.reduce(math.max) No need to make a lambda function wrapper
@michaelthornes5 күн бұрын
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Ай бұрын
Why is there no math.max that takes an array?
@thatosello1021Ай бұрын
What happened to sorting and popping?
@deadchannel843125 күн бұрын
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.
@thatosello102124 күн бұрын
@@deadchannel8431 you are right. In my defence, performance was not an object lol
@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Ай бұрын
the biggest mistake was using javascript
@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Ай бұрын
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Ай бұрын
What makes you think that a max function would need to be recursive?
@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Ай бұрын
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Ай бұрын
@@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Ай бұрын
@@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Ай бұрын
@@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Ай бұрын
@@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Ай бұрын
I will stick with traditional for loop. It works well in every languages.
@DeathSugarАй бұрын
coulda just math max as param instead of arrowing it
@Badrsh-tk4cdАй бұрын
list.max??
@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Ай бұрын
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Ай бұрын
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