Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Subjunctive
Sep 12, 2006

✨sparkle and shine✨

If your objects have a known set of relevant properties, then you can just compare those. If you want to compare equality of containers like sets, for example, then you need to worry about keys that are present in either but not both.

If you're dealing with JS objects that conform to a known protocol -- they have the same structural type -- then just do what you'd do in any language with explicit types.

Adbot
ADBOT LOVES YOU

no_funeral
Jul 4, 2004

why
Can somebody help point me in the direction of a Javascript framework that would work well for what I'm doing? The idea is that we'll have a rails app which is basically just an API, and a JS app (currently using Angular) handing an admin interface, and the user facing component.

The problem with Angular is that it may be a bit heavy-handed for what we're doing. We don't really need two way binding, right now the Angular app uses API calls to update the Rails app DB. I'm just looking for suggestions based on anybody's experience, what they liked/didn't like.

So far the list of possibilities include React, Reflux with Flux, and Knockout... I don't really have any criteria for what is best, other than ease of use, and performance(which is why I'm leaning towards React).

necrotic
Aug 2, 2005
I owe my brother big time for this!

no_funeral posted:

So far the list of possibilities include React, Reflux with Flux, and Knockout... I don't really have any criteria for what is best, other than ease of use, and performance(which is why I'm leaning towards React).

Reflux is a Flux library that sits on top of React, its a way of managing global state at the top level of the React component hierarchy. The general trend seems to be heading towards Redux, which does better at enforcing immutable state. Flux is an Architecture, thats it (though Facebook did release a dispatcher when they described the Flux architecture). Redux is based on this architecture but takes it a step further.

I've been very happy working with React + Redux, and while there's no "framework" really built around these libraries yet they are pleasant to work with and have a small enough surface area to piece together on your own.

no_funeral
Jul 4, 2004

why

necrotic posted:

Reflux is a Flux library that sits on top of React, its a way of managing global state at the top level of the React component hierarchy. The general trend seems to be heading towards Redux, which does better at enforcing immutable state. Flux is an Architecture, thats it (though Facebook did release a dispatcher when they described the Flux architecture). Redux is based on this architecture but takes it a step further.

I've been very happy working with React + Redux, and while there's no "framework" really built around these libraries yet they are pleasant to work with and have a small enough surface area to piece together on your own.

Thanks, I've been watching the videos here https://egghead.io/lessons/javascript-redux-the-reducer-function and Redux + React seems like it will end up being my recommendation. Either that, or we dive into the Angular 2.0 beta because we all hate ourselves.

I think the trouble I'm having with this is evaluating what our exact needs are (for a product that exists, but we're rebuilding it) and translating those into feature sets, and which would be most advantageous for us.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Subjunctive, I have an early JS history question for you.

Who the hell named it XMLHttpRequest, and how can I punch them over the internet? That consistency on capitalization is amazing.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
also, while you're at it, track down the guy who made getElementById and innerHTML too

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Microsoft created XHR for Outlook Web Access, to handle the HTTP requests once they stopped shipping Java. They also did innerHTML, I believe in the IE4 days when they first shipped Trident with a live DOM (which ruled) vs Netscape 4's layer-replacement model (which sucked).

gEBI was probably some XML weenie on a W3C committee, at Boeing or a French defense contractor or something. It's of that era.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
You sure? I thought MS created ActiveXObject("XMLHTTP"), so they named it correctly.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Suspicious Dish posted:

You sure? I thought MS created ActiveXObject("XMLHTTP"), so they named it correctly.

Oh, that inconsistent case. Yeah, uh, so like...that was us.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

The networking people were terrible at naming things and interface design. We used to describe it as a drawer of mismatched socks.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
how does something like that even happen without anybody catching it

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Please, you're triggering me.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

(Next time we get beer, I will tell you stories.)

LP0 ON FIRE
Jan 25, 2006

beep boop
About XMLHttpRequest - I've heard that it's a strict naming scheme where if two or more acronyms are in a row, it must flip flop between upper and lowercase (but still start off with a capital) so it doesn't look like one giant acronym. I don't like it, and what excuse do the have for getElementById?

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

No, it is not a principled thing. It was an internal-to-Gecko piece of bad naming that got exposed to the web and :smith:

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

LP0 ON FIRE posted:

About XMLHttpRequest - I've heard that it's a strict naming scheme where if two or more acronyms are in a row, it must flip flop between upper and lowercase (but still start off with a capital) so it doesn't look like one giant acronym. I don't like it, and what excuse do the have for getElementById?

This problem is why I just do all acronyms in camel case now (eg XmlHttpRequest).

LP0 ON FIRE
Jan 25, 2006

beep boop
I have an element that has nodeType 3, but I can't access its style property. What's the deal? It's a div.

Edit: Arghh.. Why is it that just about anytime I post here asking something I wasted hours on, I immediately figure it out? I was using nextSibling, instead of nextElementSibling. :doh:

LP0 ON FIRE fucked around with this message at 23:01 on Jan 12, 2016

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
Template strings are pretty rad. That is all.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Wheany posted:

Template strings are pretty rad. That is all.

Agreed. If I didn't already always use Babel for every JS probject, I'd start just so I can use template strings everywhere.

obstipator
Nov 8, 2009

by FactsAreUseless
I'm given this string and I'm trying to decide how to evaluated it:
code:
condition_str = "(user_version >= 10) || ((user_version == 1) && (version >= '10.2.0.0'))"
It's super easy with eval(), but now I'm at the step where collation matters. See that ugly rear end "version >= '10.2.0.0'"? I need a way for js to parse that string in a human readable way, where "10.2.0.0" is greater than "9.2.0.0". String comparison by default sees that the first character, "1", is less than "9", so "10.2.0.0" is considered less than "9.2.2.0".

Using collators makes this human readable comparison easier:

code:
human_readable_collator = Intl.Collator({}, {numeric: true, sensitivity:'base'});
However, that's intended for use as params into a function:

code:
human_readable_collator.compare('10.2.0.0', '9.2.0.0');
With the general <= and >= comparitors, is this possible to do? If not, this evaling of a string is gonna be a pain with garbage code regexing the condition_str to make something usable.

obstipator fucked around with this message at 19:22 on Jan 22, 2016

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Use the semver package if you can via npm install semver.

If you're working in a browser and not using a build system that allows you to use npm packages, maybe you can hack something together with the semver source.

Parsing semantic version numbers is non-trivial.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

I think you're going to end up writing a parser and simple evaluator for the small language you want to process, so that you can give the operators the meanings you want.

obstipator
Nov 8, 2009

by FactsAreUseless
Piss. Parsers are too much for my wee brain to handle for a project this small. I'm just gonna regex some poo poo to convert the special weird cases into things I can evaluate easily.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

obstipator posted:

Piss. Parsers are too much for my wee brain to handle for a project this small. I'm just gonna regex some poo poo to convert the special weird cases into things I can evaluate easily.
There's a tiny JS expression parser called jsep that probably would make this pretty trivial. It only parses expressions into an AST, not the full language, so it seems like pretty much exactly what you're looking for.

http://jsep.from.so/

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

obstipator posted:

Piss. Parsers are too much for my wee brain to handle for a project this small. I'm just gonna regex some poo poo to convert the special weird cases into things I can evaluate easily.

Using regex IS a parser.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Skandranon posted:

Using regex IS a parser.

Expressed in one of the worst ways possible, though.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Subjunctive posted:

Expressed in one of the worst ways possible, though.

Things can always be worse...

darthbob88
Oct 13, 2011

YOSPOS
Would y'all mind checking my work? A job I just applied for had a code test, to "write a JavaScript function that merges all its string arguments and returns the result", giving as an example
pre:
merge("abc", "123") == "a1b2c3";
This is my best effort, but I'm certain there's a better way, just using vanilla JS.

ETA: I've already applied, so this isn't cheating, it's just for my own education.

darthbob88 fucked around with this message at 08:41 on Jan 25, 2016

Depressing Box
Jun 27, 2010

Half-price sideshow.

darthbob88 posted:

Would y'all mind checking my work? A job I just applied for had a code test, to "write a JavaScript function that merges all its string arguments and returns the result", giving as an example
pre:
merge("abc", "123") == "a1b2c3";
This is my best effort, but I'm certain there's a better way, just using vanilla JS.

ETA: I've already applied, so this isn't cheating, it's just for my own education.

Unless I'm misunderstanding the prompt, couldn't you just do this:

JavaScript code:
function merge(...strings) {
	return strings.join('');
}

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker
That would be stupendously simple if arguments was an array. So let's make it one with Array.apply:

function merge(){return Array.apply(null, arguments).join()}

Boom. To be submitted you really need to check if an arguement can be converted into a string so you don't end up with a bunch of [Object object]s (and NaN's probably?) but at least its not using a nested loop to copy over one length strings one by one. :psyduck:

edit: or be fancy like the guy above me.

qntm
Jun 17, 2009
You've both misunderstood the prompt. Look at the example output darthbob88 supplied, your code doesn't do that.

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker

qntm posted:

You've both misunderstood the prompt. Look at the example output darthbob88 supplied, your code doesn't do that.

You're right. Yeah, I don't see an easier way of doing it then, my bad.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
well, I would first have asked them what happens when I hand them two strings of uneven length, because that seems like an obvious prompt and one they want you to ask.

Sedro
Dec 31, 2008

darthbob88 posted:

Would y'all mind checking my work? A job I just applied for had a code test, to "write a JavaScript function that merges all its string arguments and returns the result"
It is basically "zip"
JavaScript code:
function merge(...strings) {
  return _.zip(...strings)
    .map(arr => arr.join(''))
    .join('');
}

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Sedro posted:

It is basically "zip"
JavaScript code:
function merge(...strings) {
  return _.zip(...strings)
    .map(arr => arr.join(''))
    .join('');
}

The point of the exercise is to show he can do the logic himself, not let Lodash handle everything. Yes in practice it's good not to reinvent the wheel, but sometimes you want to see if someone actually understands how a wheel works.

Sedro
Dec 31, 2008

Skandranon posted:

The point of the exercise is to show he can do the logic himself, not let Lodash handle everything. Yes in practice it's good not to reinvent the wheel, but sometimes you want to see if someone actually understands how a wheel works.
Yes, I know. Just pointing out the common name of the operation, which is a standard library function in most languages.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
when did underscore get renamed to low-dash?

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Suspicious Dish posted:

when did underscore get renamed to low-dash?

When it got forked by someone who can design an API worth a drat.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Suspicious Dish posted:

when did underscore get renamed to low-dash?

lodash has been the better alternative to underscore for years now.

Yes, that's classic JS community for you.

Adbot
ADBOT LOVES YOU

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I never really followed underscore / lodash because most of the utility functions seem nearly pointless or so obvious to write to not matter.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply