Vaughan Hilts

JavaScript

Topic: Anything JavaScript, ECMAScript including Node, React, ...
May 26, 2019 00:29
Not sure either. I'm definitely not an expert. :( I write mostly Vanilla JS.
May 26, 2019 00:00
Good to know!
May 25, 2019 23:58
:)
May 25, 2019 23:54
(req, response) : RequestHandler
May 25, 2019 23:53
I think you put it after the arrow function
May 25, 2019 23:52
So type the function as RequestHandler
May 25, 2019 23:52
The entire thing is RequestHandler I believe
May 25, 2019 23:51
So specify the type
May 25, 2019 23:51
You won't; you have to add typings
May 25, 2019 23:47
VS Code should be able to show you how to interface with it for example
May 25, 2019 23:47
Are you not using an IDE with autocomplete?
May 25, 2019 23:44
My turn now. :) Can anyone tell me if it's still true that node is using UCS-2 encoding for their strings under the covers?
May 25, 2019 23:43
This is more up to date: npmjs.com/package/@types/express
May 25, 2019 23:42
It's probably a "Request"
May 25, 2019 23:42
@SuperUberDuper You can look at the TS definitions for example github.com/DefinitelyTyped/tsd/blob/master/typings/request/…
May 25, 2019 23:40
With this, you should be able to figure out the differences between two different implemenations and how they are good & bad
May 25, 2019 23:39
Sure, regexp would still need (blue|yellow|big|small) etc.. anyway, you will figure it out when you compare the two
May 25, 2019 23:39
You will note the FSM solution delegates to some info on a table to figure it out and uses functions where it can't figure it out (i.e: a value that is dynamic, such as a color, instead of checking all colors, we just ask the browser if it's valid)
May 25, 2019 23:38
So if the attribute was "size" and the value was "52px" your regexp would probably look like (blue|cyan|yellow|12px) etc
May 25, 2019 23:38
The regexp version has a couple deffiencies from a full FSM version in that it can't branch or parse from different states, for example if it encounters "color" it can't tell to just search for "colors" in the next regexp
May 25, 2019 23:37
@Thaenor Here is your regexp version: codepen.io/anon/pen/PveOmr
May 25, 2019 23:30
Let me link you to a an easier one as well, give me a min or two
May 25, 2019 23:29
You can find the examples at the bottom
May 25, 2019 23:29
Hopefully it makes sense
May 25, 2019 23:28
const lastItem = arr[arr.length - 1]
May 25, 2019 23:26
You certainly can, but then you don't get names for them
May 25, 2019 23:26
@cubesnyc You mean for mien?
May 25, 2019 23:25
You could do it with regexp as well, but it might be a bit harder
May 25, 2019 23:24
This obviously won't handle things like:

1. "the square AND circle" You're going to need NLP or some dirtier parsing to do this
2. You will have to implement things other than "color" on your own but it should be easy enough to do
May 25, 2019 23:24
Here you go
May 25, 2019 23:16
Almost done
May 25, 2019 23:06
Regular expressions like easy of tracking state
May 25, 2019 23:06
One moment
May 25, 2019 23:06
You sure can
May 25, 2019 23:04
This can all be handled the same using a simple FSM
May 25, 2019 23:04
I didn't but it doesn't really matter
May 25, 2019 23:02
It might take more like 5 mins though :laugh:
May 25, 2019 23:02
Let me whip you up an example using a FSM
May 25, 2019 23:01
Are you familar with a finite state machine?
May 25, 2019 23:00
Give me 2 mins
May 25, 2019 23:00
No, it's fine
May 25, 2019 23:00
Why don't I just write you an example?
May 25, 2019 23:00
Actually
May 25, 2019 23:00
Let me edit this a bit
May 25, 2019 22:59
No, just write a loop.
May 25, 2019 22:58
Scan a string for your command and then scan for other things after that
May 25, 2019 22:58
If there's a finite amount and you want something specific, then just ask for it
 

Trash can

Like the recycle bin, but trashier.
May 25, 2019 22:59
```
const tokenizedUserWords = input.split(" ");

let STATE = 0;

const STATE_LOOKING_FOR_COMMAND = 0;

tokenizedUserWords.forEach((word) => {
switch(STATE) {
case 0:
}
});

```