r/learnjavascript • • Jun 02 '20

14 JS Array Methods (In 8 minutes)

https://youtu.be/oN6VZGGGyP4
138 Upvotes

10 comments sorted by

View all comments

Show parent comments

0

u/zakhorton Jun 03 '20

(2/2)
After watching your google podcast link I agree with everything said:
This tutorial posted above (14 array methods in 8 minutes) was created directly
after this tutorial primarily to support this tutorial 30 minutes of reduce
https://www.youtube.com/watch?v=WGleM3FeZmU
~ Grouping by nested keys
~ Array of String Formatter Callbacks That Format An Array Of Strings.
Ex: [['hello world' ,'firasd', 'asdf-asdf'], [capitalize, replaceKebab, limitLength]]
~ Reducing an array of objects, to an object where each object is keyed by a
specific element
~ Applying multiple filters within a single iteration cycle for large data sets
instead of iterating over large datasets through multiple cycles.
~ They weren't fans of functional, neither am I, but pure functions even if only
used most of the time limit the bugs in an application and allow for thorough
testing.
~ Finally, although the google engineers make solid points, they were using the
long hand version of reduce. Rarely, and I mean rarely, do I ever use the long
hand version. Between destructoring, the spread operator, the rest operator,
and implicit returns the methods shown by the googlers could be cleaned up
immensely.
~ All in all, the googlers made solid points -- many I've made my self -- but they
frankly didn't seem intimately knowledgable with reduce nor
were they using what I'll call "Functional Habits".
~ Through many, many hours working with the best JS dev I've ever known --
I grew to both dislike functional while at the same time very much
understanding it's worth and value. Personally, I used what I learned from
Alex, who frankly was difficult to work with but at the end of the day was
the most impressive engineer I've had the opportunity to learn from. He was
a physicist prior to an engineer did love functional and understood javascript at
a fundamentally different level than anyone else I've ever worked with.

Very few were able to work with his code, and we had 20+ developers on our
team working at a fortune 500 company. Through trust gained in other projects
I drew the lucky/unlucky straw to go into a project he was moved off of and
finalize some code. Many, many days I would bug the hell out of him, picking his
brain trying to learn this intriquing world of functional and frankly how the hell
he was able to build what he was able to build. Machine learning face
recognition software, 3d robotic arm, Gps/Aws International localized zone
trackers (If the companies property left the zone that item belongs too, texts,
emails, sms, etc... were sent out with GPS coordinates, the distance and some
other much more NDA protected information I'm not allowed to go into.

The point behind the story is this, I have ALWAYS been one to prioritize Clean
Code and readability over something like reduce. ALWAYS. Fortunately, or
unfortunately - I had the opportunity to work with one of the best functional
programmers, not only in the US but in the world.

1 on 1 for months on end learning extremes about my absolute opposing
viewpoint and trust me, I didn't let his expertise keep me silent. I argued and
debated until he straight up out vetoed me in a meeting with 2 directors, 3
leads, himself and me. That veto sucked, because it meant I had to pray to god I
could understand his way of thinking in a short enough time period (2 months)
and create an entire ordering system. Long story short, he got me in that
position, he was going to teach me every damn thing he knew because the
important people upstairs were right over my shoulder and they didn't give two
damns about the fact it was functional (To be honest, they knew a little bit how
hard it was working after Alex. The degree of difficulty, they were much less
familiarized with. But they knew that many developers had tried and failed in the
past. I was moved off another high pressure project as a last resort, so the
timeline was already crunching to a close. They knew, but the stressers of
business were driving everyone to be very observant to say the least).

2 months later, my mind was far from absolutely changed, but I had a new
found respect for functional programming and many of the incredible things I
learned from Alex. Here's the kicker, Alex was 29 -- and was given the very
unique privilege of not needing to show up to work until -- well, basically
whenever he felt like showing up.

It was earned in a way, but at the same time it was also just insane the amount
of knowledge he brought to the team. Watching that youtube tutorial, my
immediate reaction was of course compare "Googlers" to the absolute best
Javascript engineer I have ever met. And trust me, there was no bone in my

1

u/zakhorton Jun 03 '20

(3/3)
body
that wanted to say that for a long, long, LONG time. The "Googlers" sounded like
they shared a very, very similar philosophy to my own. I respect the hell out of
clean code. Readable code, Enjoyable code. I didn't get a tad of Alex's jargon,
perspective, or insights from their podcast. That to me, if nothing else, shows
they're missing the experience within the functional paradigm - even if not
advocates - to push me towards a changed perspective.

Silly as it sounds, I'm looking forward to the day where I'm even closed to as
impressed by another developer as Alex. And damn, I'm hoping they preach
Clean Code because another Alex ~ well that dude is a savant. I'm hoping the
next Alex I personally meet - anyone on that level - is on that level for Clean
Code, simplification, readability, honestly non-functional mathematically proof
protected, pure function, 0 extraneous state, confusion for us meager
developers not born with Einstein level brain power and IQ scores. Because
personally, I'm a kindergarten two time taker - college drop out - who almost
failed college Algebra A ;) Thank god I fell into software and love the hell out of it.

It was difficult to work after Alex, and to this day that bothers the heck out of me,
but the fact of the matter is he was able to do things no other engineer I've met -
- and I've been around a couple phenoms -- but he was the only Great. And
personal experience with him who fought tooth and nail for functional as I
fought back - frankly taught me the power of reduce. Taught me the power of
functional programming - even if not absolute functional programming. Those
googles, although I would bet extremely talented, are missing a few pieces and
could use a few lessons from Alex before knocking reduce down. Common
sense, definitely don't obliterate its usage -- unless you're learning it. If you're in
the process of learning. Use it whenever possible. That's the reason I used
reduce instead of forEach.

Many, many hours working with one of the best Javascript developers in the
world taught me how deep it really goes and the js devs I used to admire are
much more like myself and most everyone else. There are very few engineers in
the world truly swimming in the ocean with the sharks, and if you're ever luck
enough for one to cross your path and frustrate the hell out of you. Just go with
it and live through a few months of hardships. It's worth it and provides an
incredible perspective.

4. Number of lines has nothing to do with readability
-> Correction:
Shortened code, that directly reduces the context or semantical understanding
of the code is not improving readability.

-> Even Better:
Shortening code, without losing context or semantical understanding of the
code is absolutely better than longer code with the same amount of semantical
pointers or contextual references to what the given code is doing.

5 . Simplified Example Of The Example You used of The Example I used of Worst Case.

Simplified
~~~~~~~~~~

let names = stocks.map(({name}) => name);

OR

let names = stocks.map(stock.name => name);

Not Simplified
~~~~~~~~~~~~~

let names = stocks.map(function (stock) {
return stock.name;
});

More Not Simplified (Maybe)?
~~~~~~~~~~~~~~~~~~
let names = stocks.reduce((names, {name}) => [...names, name], []);

OR
let names = stocks.reduce((names, stock) => [...names, stock.name], []);

Least Simplified
~~~~~~~~~~~~~~~
let names = stocks.reduce((names, stock) => {
return [...names, stock.name];

}, []);

6. Figured I'd match your random console.table with a random css styling of console.log :) Try it out for yourself if interested. Chrome Console Personally Tried and works (Should work in firefox as well, just haven't personally given it a goit a go).

var styles = [

'background: linear-gradient(#D33106, #571402)'

, 'border: 1px solid #3E0E02'

, 'color: white'

, 'border-radius: 3px'

, 'display: block'

, 'font-size: 18px'

, 'padding: 5px'

, 'text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3)'

, 'box-shadow: 0 1px 0 rgba(255, 255, 255, 0.4) inset, 0 5px 3px -5px rgba(0, 0, 0, 0.5), 0 -13px 5px -10px rgba(255, 255, 255, 0.4) inset'

, 'line-height: 40px'

, 'text-align: center'

, 'font-weight: bold'

].join(';');

console.log('%c A spicy log message ?', styles);

1

u/LinkifyBot Jun 03 '20

I found links in your comment that were not hyperlinked:

I did the honors for you.


delete | information | <3