« first day (2986 days earlier)   

12:25 AM
@Meredith what do you think of my hat, it's bigger. Vogue says it's all the rage on SO.
 
12:36 AM
don't hate me because I'm beautiful
 
12:51 AM
@Rick I cant tell what it is
does mine show up
 
@BenBeri You might get bonus points for using arrow functions if it's an interview. const calc = (x) => (y) => x + y;
 
parentheses? ew
 
const calc = x => y => ( x + y );
 
calc = (+)
get on my level
 
1:06 AM
@KendallFrey it's a point of contention at work too... our current linting rules say parenthesis if it has more than 1 arg, or if it has a {} body
but none if it's single argument and either one line or with a () or jsx body
i prefer the consistency of just always putting parenthesis
 
That shouldn't be a linting rule, it's a syntax rule
 
just like i prefer always putting semicolons
it's linting for the body one
you can have multiline funcs with no parens
 
huh?
 
i'm pretty sure you can...
yeah like this:
const fatadd = x => {
  return y => {
    return x + y;
  };
};
 
oh that's just single param lambdas though
 
1:09 AM
valid, but our linter says you need parenthesis around the arguments
 
your linter is dumb then
 
i think it's just the airbnb rules
that's what the original people picked as a default
eitherway, i prefer consistency so i always use parenthesis
and i always use semicolons
and i always use {}
none of this if (condition) return nonsense
I don't mind it being on one line, but I write it in full. if (condition) { return; }
 
So what are some alternatives to having jquery append a script tag?
 
appending it without jQuery
I'm not sure I'm following the question. do you have something more specific in mind?
 
Can you overwrite (not read) http only cookies?
 
1:30 AM
I'm trying to add a stripe payment button to an element, but ill try it without jquery
 
@david Even in arrow functions?
When you dont need them
I often go way out of my way to avoid the (x) => { return x } style
 
@Meredith yeah i'm the same way. I guess I justify that in my head by saying they're different forms
it's not just a case of optional punctuation, it's also a whole optional return
 
Yeah I hate it
It really disrupts the flow of the code
 
@Meredith here's a fun question: How would you write a function to turn [['a', 1], ['b', 2]] into {a: 1, b: 2}? Like a reverse Object.entries.
(without using Object.fromEntries() because that's still firefox only)
 
1:47 AM
Oh that's just converting a keyword list into a map
pretty common problem 1 sec
 
yeah it's incredibly common
and everyone uses a reduce
 
Do you want me to use something else?
 
but getting it to be succinct is hard
no reduce is fine
reduce is probably best
it's just an interesting problem because it's so common I feel like it should have a 'best' answer, but I am still unsure what that 'best' answer is.
 
Oh is this a test of how far I can go to avoid using { }
 
Object.assign({},...arr.map(([k,v])=>({[k]:v})));
:D
 
1:50 AM
The answer is list |> Enum.into(%{})
 
@rlemon that's something I haven't seen before...
 
you could just spread the whole thing again
 
and it's interesting because it doesn't mutate anything
 
but I wanted to use Object.assign
!!> ({...Object.assign({}, ...[['a', 1], ['b', 2]].map(([k,v]) => ({[k]:v})))})
 
@rlemon {"a":1,"b":2}
 
1:51 AM
oops
well, I guess not
ignore me
 
wait what's wrong? that seemed to work fine?
 
it did, but it wasn't any different really.
 
the extra object spread wasn't needed...
ah okay
 
i stole that from stackoverflow btw
 
>< i meant in javascript
 
1:57 AM
I hate for comprehensions
look how unreadable that is
list.reduce((map, [k, v]) => ((map[k] = v, map)), {})
is the only true solution
 
yeah
good old comma operator
it's what I use too... but people get upset when they see it
 
I mean they should get upset cuz it's awful
 
is it though? what's awful about it?
 
It's just so hard to read
especially with reduce
hard to tell if map is the initial acc or not
 
morn
 
2:01 AM
reduce is always going to be harder to read than more specific functions like map and filter
but i think the body is fairly readable
 
It depends
Like in this case it's only hard to read cuz we didn't abstract out a Map.set
 
It's not readable, I use to use reduce with closures for the second hash, people got really upset
 
the 2 issues I agree with are 1) Very few people know about the comma operator, so that makes it impossible for them to understand. and 2) Functional purists don't really like mutating the arguments to a function, so modifying map isn't ideal.
 
In reality the solution is just
npm install --save immutable
 
a version i've used that passes the linter and avoids those 2 issues is this:
(a) => a.reduce((o, [k, v]) => Object.assign(o, {[k]: v}), {});
no comma, no mutating the input object
 
2:04 AM
I stay away from the Object/Function methods when I can
 
but many many intermediate objects
 
Object.assign is just one function I really don't like
 
I don't like it it either, "for in" would suffice
 
@Meredith that is truly terrible
 
Yeah it's rough
 
2:08 AM
Why would you ever need to do that? Never make code complicated. Complex is okay, but that is definitely complicated.
 
What
it's pretty common
 
yeah @DavidKamer it's an incredibly common function to need to write
 
Clarify,you mean reduce, or the way it's used?
 
turning arrays into objects
 
Well yeah, but I mean that implementation
 
2:11 AM
Reduce is usually good for maintaining immutability. How you use it, is up to you
 
To avoid having to type return
 
OMG, this is so far from any scenario that doesn't involve entirely bad arch that I'm having a hard time thinking of a way to do this without an object that would need it
 
What
 
You need return if you're going to need to use some conditional logic
 
The OMG was automatically capitalized. On mobile lol
 
2:15 AM
Just use a shit ton of ternaries
 
@Meredith the architecture would have to be bad overall to need code like this
 
Usually you use it for small one of scripts that for example scrape an html table or reads a csv file and spits out json
 
@DavidKamer no it wouldn't. Building maps from arrays is incredibly common. Most often to give O(1) lookup if you're prepping for a meaty algorithm
 
@Meredith that doesn't sound like good arch lol
 
I use to do that, but it pissed people off.
 
2:17 AM
It's useful if you don't want to pay for API access
 
@david maybe, but why would you need to put it in a map? Who put it in array?
@Meredith fair enough
 
It is also the best de-dupe algorithm ever
to_list(to_map(list))
 
That is the answer I was looking for lol
 
@DavidKamer have you ever called an API? the results usually come back as arrays
 
@david oh yeah, but what API returns trash that needs that piece of code
 
2:20 AM
o_O
 
@david seriously I'll give you (insert something against COC,
 
I mean it's certainly informal
 
) if you tell me the API
 
I got a hat
 
But fundamentally that's how you would do it
 
2:21 AM
yippe
 
@JBis good jarb
 
@DavidKamer I don't think you're understanding the problem. Using maps/objects to order data is INCREDIBLY common. Lets say you have a list of users, and you have some kind of matching algorithm that needs to get all the users of a certain country, or all the users with certain interests. You could call [].filter over and over, but in a complex algorithm that quickly spikes your complexity. Using maps to index the data lets you turn all those O(n) searches into O(1) lookups.
 
@david I'm not arguing with you.
 
@DavidKamer thanks
Whats better?
1. Copy all of the innerHTML to a variable and change an attribute for each element in the variable, then replace the original innerHTML with the changed variable
2. Iterate through each element inside changing the attribute, but accessing the DOM lots and lots of times?
 
You should get the retro shades and put them on your toes
*tie
@JBis
 
2:32 AM
how?
 
I think you just star an old Post or do something with an old Post
 
I googled something like "how to sort an array stack overflow"
and upvoted it
 
Lol nice
@JBis probably 1
Bc queries are expensive
IfI understand you
But profile each for your use case
 
does that taste good @Meredith?
 
2:38 AM
depends on how stoned you are i guess
 
Wat omg lol
Just some koolaid mix in the background ready to add as a spice lol
 
Who let francis in here
 
who is francis
 
@Meredith the Pope
 
Oh is that still a thing
 
2:53 AM
Apparently
 
@KendallFrey @Meredith see the Pope
 
why does he keep pouring mountain dew on the bacon
when its gonna go into a pot of mountain dew
 
@Meredith wat? The lacks to much context for me
 
3:03 AM
idk theyre making mountain dew soup
 
@Meredith 1st world problems
 
with bacon and marshmallows
 
#toothdecay
 
epic meal time is still making videos lol
 
@DavidKamer ah
@DavidKamer grrr I did #2.
 
3:09 AM
remember in like 2010 when everyone on reddit was making those sandwiches
 
@JBis I mean it's probably a negligable difference
@Meredith I can't remember 2014. How can you remember 2010 lol
 
@DavidKamer Not necessarily if its 100's of elements
 
do we still get hats for gold badges?
 
@JBis well yeah. At that point you should have avoided it all together though
 
@10Replies yes very cool. I find on a 1-10, adults will tend to pick 2,3, or 5, while kids will choose 9 or 10.
@DavidKamer true. true.
 
3:22 AM
@JBis I always choose zero
 
@10Replies Well arrays do start there...
 
cough do we still get hats for gold badges cough
 
 
2 hours later…
Jon
5:14 AM
Hello Guys,
Can anyone help me on this
https://stackoverflow.com/questions/53756798/add-elements-on-click-on-dynamically-generated-a-tag-with-dynamic-id
 

« first day (2986 days earlier)