Комментарии:
flatMap is NOT like .flat() .map(), it's like .map() .flat(), very different!!
Ответитьsomething is very off with the camera and sound sync. looks scary.
ОтветитьKyle, thank you for speaking so clearly.
Im not that good at English but I can completely understand you, that's why I subbed to here years ago.
i think you have done enough intros kyle. just keep in the bio.
ОтветитьgroupBy is top!
ОтветитьWho cares what you are talking about, I already heard about it and still don't use it 😢 I think I need to visit coding interviews to practice that more often😂
ОтветитьCSS starts calling everything start and end Javascript starts using left and right. Classic.
ОтветитьI used most of these method quite frequently, they are super useful. My fav one is reduce(), it's very useful when you want to reduce the array to a value and then use that value, also I got headache many times from using it :)
ОтветитьThe main question is - are they faster than simple for() loop ?
I have been playing with the js loops lately and it seems that for array of 10 millions random numbers the for() loop is much faster than: filter, find, forEach, map and reduce.
And by faster i mean like 10x times faster.
The only method that was faster was the build in sort() method. That worked better even then insertion sort/ merge sort/ or quick sort Algorithm made in JS for loop - i am not sure but i suspect this is because of V8 chromium engine which uses C++
Wow, didn't knew about .with (this one is very useful!), .groupBy, start/end arguments of .fill, also didn't knew you can add argument like depth to .flat and about Set method, tysm!
Ответитьyou really need to try console.table() instead of console.log() to show array objects in these awesome videos
ОтветитьPlease explain a bit slowly, you are explaining like you are running a sprint.
ОтветитьIs there a new way to get the last item in the array instead of the old array[array.length - 1]?
ОтветитьGreat video! Keep it up 💯
ОтветитьHow about performance of each function
ОтветитьI knew about half but I always forget about them. Thank you for the refresher. The toSorted() and .toReverse() are my favorite
Ответить70% watching here is dude i believe, stop winkking!!!! blushed damn it!!!
ОтветитьSolution looking for a problem...
ОтветитьHaving reduceRight makes it sound like default reduce is wrong
Ответитьwait general fixed job dom
Ответитьwait general fixed job dom
Ответитьpart yield function set key specify task
Ответитьto vs easy enable live
Ответитьpost none if code expire
Ответить`groupBy` alternative for node.js users:
function groupBy(array, key) {
return array.reduce((groupedItems, item) => {
const keyValue = item[key];
if (!groupedItems[keyValue]) {
groupedItems[keyValue] = [];
}
groupedItems[keyValue].push(item);
return groupedItems;
}, {});
}
let groupedByName = groupBy(people, 'name');
console.log(groupedByName);
I use .fill when I just want to map over a range of numbers. Mapping over new Array(x) doesn't work since there aren't any keys. But you can do
new Array(x).fill(0).map((val, index) => index)
It’s good to be a developer on Mac😎
Ответитьhey, did it come into your mind of building hair gel products lately? great tutorials always
ОтветитьI use lodash for most of this functionality.
ОтветитьThe namings for some of these methods are really confusing
ОтветитьNice, but who th thought "unshift" was a good name for that???
ОтветитьVery noob
ОтветитьIs there a method to "flat" an object? That is, to make a deep copy of the entire object made of other objects?
Ответитьthe with method is kind of superfluous because we can already use the destructuring technique. Like, putting something at the beginning
let inTheBeginning = [ newThing, ... people]
let inTheEnd = [ ... people, newThing]
But if the idea is to insert some value somewhere in the middle of the array, the with is handy indeed
Curiously, it's note supported in Node.js. Although it's very easy to implement
function groupBy(list, keyGetter) {
return list.reduce((ac, curr) => {
const key = keyGetter(curr);
ac[key] = ac[key] || [];
ac[key].push(curr);
return ac;
}, {});
}
Most shocking referral, Kyle uses windows
Ответить.groupBy is super useful, but unfortunately still not supported in a lot od environments:/
ОтветитьThere's one other reliable, though hacky way of checking whether something is an array: Object.prototype.call(people).toString() === "[object Array]";
ОтветитьThis video taught me that someone still uses a PC. Wild.
Ответитьyou explain these concepts better than the majority of the teachers out there!
ОтветитьI really don't see the point of `array.at`.. even for negative indexes, I would prefer `array[array.length - x]` or am I too old-fashioned? :o
ОтветитьI’m excited about the set theory operators. I hope that eventually gets full support across major browsers.
ОтветитьImportant to note that the .fill method behaves differently when you fill the array with objects(including arrays), where it actually fills the array with a REFERENCE to the original object, so that if you perform a mutation on any of the objects in this array, it will perform the same mutation on all the elements in the array. Was stumped by this until ChatGPT helped point me to the docs on MDN...
ОтветитьIt's about time they added those Set difference/intersection methods!
Ответитьoh sh- i have to change my .sort() to .toSorted()?
ОтветитьС*ка, до слёз! Даже плюсик поставил от нахлыва чуйств :D
ОтветитьThe one thing I felt like was missing from this video is that you usually make sure to provide example situations in when you might use the code, and more importantly why. Otherwise, learned a lot of cool new stuff I will try to find a use for. Thanks!
Ответить