« first day (3459 days earlier)      last day (1472 days later) » 

12:44 AM
what is this syntax
as BookingDetails;
the as
specificlly
 
 
2 hours later…
2:17 AM
where is everybody
i am lonely and I need to code
 
2:50 AM
@ChristianMatthew typescript?
 
yes
high human
it's been days
lol
but yes it is typescript... ahhh is that what it is
 
got it. treat this AS this type
but can it be a type switcher?
for example going from an int to a string
 
 
4 hours later…
6:42 AM
what is this syntax?
const data = {
  item1: { key: 'sdfd', value:'sdfd' },
  item2: { key: 'sd33fd', value:'sd33fd' },
  item3: { key: 'sdfd', value:'sdfd' }
};

// const { item2 } = data;

console.log(item2);
 
which part
 
why does item2 become filtered?
the part that is commented out
 
that deconstruct?
 
||mdn object destructuring
 
i thought it was just the spread operator but I guess this is in conjunction of the spread operator
cool
 
yep a little different from spread
but you can do some really weird stuff using destructuring with spread
I've seen people use it in really creative ways, e.g. omitting properties
99% of destructuring is not used with spreading though
||eval const foo = {a: 'one', b: 'two', c: 'three', d: 'four'}; const {c, ...bar} = foo; return bar;
 
@forresthopkinsa "SyntaxError: Invalid or unexpected token" Logged: ``
 
@forresthopkinsa {"a":"one","b":"two","d":"four"} Logged: ``
 
6:47 AM
missing quote
anyway, it's a very succinct way to omit a prop
 
7:04 AM
ok there is one bad thing about this
const data = {
  item1: { key: 'sdfd', value:'sdfd' },
  item2: { key: 'sd33fd', value:'sd33fd' },
  item3: { key: 'sdfd', value:'sdfd' }
};

console.log(data.item2);

let blue = data.item2

const {blue } = data;

console.log(item2);
you need to know the property name upfront
i need to have it resolve first
 
7:54 AM
I can't get this to work and it's odd to me
const data = {
  item1: { key: 'sdfd', value:'sdfd' },
  'item2': { key: 'sd33fd', value:'sd33fd' },
  item3: { key: 'sdfd', value:'sdfd' }
};

// console.log(data.item2);

const blue = 'item2';

const { item2: red } = data;

console.log(red);


const o = {p: 42, q: true};
const {p: foo, q: bar} = o;

console.log(foo); // 42
console.log(bar); // true
i cant' use blue to assign the string
but i can use the string directly
 
Anyone ever had any problems cloning code from git with UTF-8 code in a windows machine? My code is comming as ASCII, so some classes with names in Kanji become ASCII equivalent characters and it won`t compile. I wonder if anyone had a similar problem before
I didn`t have this problem when using mac, but for this project I have to use a windows machine
 
 
2 hours later…
10:10 AM
Hi devs. I'm using dexie.js to implement offline data persistence in an electron app. I want to sync the data with a remote mysql database, I have the table structure like the one of dexie and using a traditional sql query I'm able to put the data from the app node.js backend, but this will happen on every submission and I want only to sync data once a time or on a button click. I'm reading the dexie docs and I see that there is a way, but I'm not sure on how to proceed
 
@guggio Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
https://dexie.org/docs/Syncable/Dexie.Syncable.ISyncProtocol
They say that is needed to implement this interface, but it's not clear for me where I need to use that code and how I will connect to the database, anyone has suggestion?
 
 
2 hours later…
12:29 PM
  React.useEffect(() => {
    const intervalId = setInterval(() => {
      const yes = createAnimatedYes();
      const newActives = Array.from(activeWords);
      newActives.push(yes);
      setActiveWords(newActives);
    }, 150);

    return () => clearInterval(intervalId);
  });
I got this hook to create animated DOM elements. The animation of them takes 3.25 seconds total, so after 3.25 seconds, I want to start removing the elements from the activeWords. Problem: That thing creates a closure of the array and when I do something like
setTimeout(() => {
  const newActives = Array.from(activeWords);
  newActives.shift();
  setActiveWords(newActives);
}, 3250);
I am doing the changes on an old array and setting it as new state, effectively removing all elements added to the actual state in the delay
Is there a decent way of handling this? Clearing older entries in the state with an interval like that but doing it on the current state instead of an older one?
 
 
3 hours later…
3:28 PM
hi good morning
this method of deconstructing seems to be pointless
 
morn everyone o/
 
const data = {
  item1: { key: 'sdfd', value:'sdfd' },
  'item2': { key: 'sd33fd', value:'sd33fd' },
  item3: { key: 'sdfd', value:'sdfd' }
};

// console.log(data.item2);
let test = "item2"

var blue = JSON.parse(' {"item2": { "key": "sd33fd", "value": "hehehe" }}');

const { 'item2': red } = data;

console.log(red);
 
lol I just realized that the files I am having problem with have nothing to do with git at all
 
i have to use the property in order to deconstruct it. but not really it's name of the property
that's dumb
 
the team who developed this system before, encoded them in Shift-JIS (Japanese characters encoding), they should`ve been using some japanese computer brand or something when developing lol
My dell computer can't read that for s***
and since its a .net project I cant use my mac for that
 
3:32 PM
i want to do this
const data = {
  item1: { key: 'sdfd', value:'sdfd' },
  'item2': { key: 'sd33fd', value:'sd33fd' },
  item3: { key: 'sdfd', value:'sdfd' }
};

// console.log(data.item2);
let test = "item2"

var blue = JSON.parse(' {"item2": { "key": "sd33fd", "value": "hehehe" }}');

const { test: red } = data;

console.log(red);
 
@ChristianMatthew hmm
then why not just do it
 
hmmmm indeed
it won't work
 
const test2 = data[test];
 
yea that won't work
also, the point is I don't know what the object is. I am trying to filter it out
i only know the string name of item2
const raw = {
  item1: { key: 'sdfd', value:'sdfd' },
  item2: { key: 'sdfd', value:'sdfd' },
  item3: { key: 'sdfd', value:'sdfd' }
};

const allowed = ['item1', 'item3'];

const filtered = Object.keys(raw)
  .filter(key => allowed.includes(key))
  .reduce((obj, key) => {
    return {
      ...obj,
      [key]: raw[key]
    };
  }, {});

console.log(filtered);
see this works
let blue = 'item1';

const allowed = [blue];

const filtered = Object.keys(raw)
  .filter(key => allowed.includes(key))
  .reduce((obj, key) => {
    return {
      ...obj,
      [key]: raw[key]
    };
  }, {});

console.log(filte
 
 
1 hour later…
5:14 PM
||> const obj = { key1: 1, key2: 2, key3: 3 }
const allowedKeys = ['key1', 'key3'];
Object.keys(obj).forEach(key => {
    if(!allowedKeys.includes(key)){
         delete obj[key];
    }
});
console.log(obj);
 
@JBis "ReferenceError: allowKeys is not defined" Logged: ``
@JBis undefined Logged: {"key1":1,"key2":2}
@JBis undefined Logged: {"key1":1,"key3":3}
 
@ChristianMatthew ^^^
 
huh
i got it working
 
that filters keys
 
5:35 PM
Hi guys
 
@devMariusz Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
no it filters by key
see how the object is there and it is referencing the key to the key's property
 
I have little problem with sellenium:
this return true (this is good):
const x = await driver.executeScript(`return /[\S\s]*([0-9]?[0-9]+)[ ]+([a-żA-Ż]+)[ ]+[a-żA-Ż]+[ ]+([0-9]?[0-9]+:[0-9]?[0-9]+)[\S\s]*/m.test('blabla3 kwietnia o 22:28blabla');`)
but this return false:
const x = await driver.executeScript(`return /[\s\S]*[^0-9]+([0-9]{1,2})[\s]+godz[\s\S]*/gm.test('blabla8 godz.blabla');`)

When I tested this regex in the browser console, both tests were true

What is wrong?
 
May I have help with understanding Kadane's algorithm implemented in JavaScript?
 
5:52 PM
Who's Kadane and why should I care about their algorithm?
 
JBis, I don't know who he is, but it's a way of finding a condition among all possible combinations in an array.
Here's an implementation in Python, but I need help using it in JavaScript: garysnotebook.com/20190730_1
I think it's Joseph Born Kadane, statistician: en.wikipedia.org/wiki/Joseph_Born_Kadane
 
> Maximum Subarray
Seems like a problem I'd never have but ok. Implementation seems simple enough, what trouble are you having?
 
It's #121 in LeetCode. I'm doing it before 122, today's prob
Say you have an array for which the ith element is the price of a given stock on day i.

If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.

Note that you cannot sell a stock before you buy one.
My problem is knowing how to approach this. My first thought is to loop the first index with every following index, then second index with every following, etc.
 
0
Q: Unexpectedly misinterpreted regex in Selenium JavaScript

devMariuszI have little problem with regex in sellenium: this return true (this is good): const x = await driver.executeScript(`return /[\S\s]*([0-9]?[0-9]+)[ ]+([a-żA-Ż]+)[ ]+[a-żA-Ż]+[ ]+([0-9]?[0-9]+:[0-9]?[0-9]+)[\S\s]*/m.test('blabla3 kwietnia o 22:28blabla');`) but this return false (i need re...

 
Is your question about implementing that algorithm or coming up with the algorithm in the first place @Matthew?
or designing your own solution (algo)
 
6:05 PM
I have the algorithm, but I don't understand it. I can work more on it and then ask for help in implementation.
It looks like you have a current_value which changes if the new value is higher.
You return the highest value that remains.
I was doing CSS and DOM manipulation, a little Java in backend, until recently. Now I'm trying to do the algorithm problems for job interviews and find I'm really rusty at this.
 
Alright i think i get it
Do you have a specific question regarding the algo?
Here's a python implementation from wikipedia
def max_subarray(numbers):
    """Find the largest sum of any contiguous subarray."""
    best_sum = 0
    current_sum = 0
    for x in numbers:
        current_sum = max(0, current_sum + x)
        best_sum = max(best_sum, current_sum)
    return best_sum
const nums =  [ -3, 8, 10 ]
Sum of previous subarray [-3] = -3
We know that no matter what the next numbers are a -3 added to the sum isn't going to increase their value because it is negative
@Matthew Is this at all making sense?
10 messages moved to Trash can
5 mins ago, by JBis
We know that no matter what the next numbers are a -3 added to the sum isn't going to increase their value because it is negative
^ that is the most important part of the algorithm
 
6:33 PM
function max_subarray(numbers){
 
const nums =  [ 3, -2, 8, 10 ]
sum of [3, -2] = 1
-- we know that whatever the next numbers are, a 1 is going to increase it's value --
same logic but in reverse ^
 
@Matthew Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
 
function max_subarray(numbers){
 best_sum = 0;
 current_sum = 0;
 for(let x of numbers){
   current_sum = Math.max(0, current_sum + x);
   best_sum = Math.max(best_sum, current_sum);
 }
  return best_sum;
}
 
1 message moved to Trash can
 
@Matthew looks good
 
6:36 PM
oh, I need to declare variables in JS. no need in Python?
 
well you should use let but its not required
 
Does this algorithm include combinations between non-contiguous elements?
 
no
 
I think the key in this problem is finding the largest combo from non-contiguous elements, where the first element must always precede the second, but not necessarily subsequently.
And it's only a profit if the second element is higher than the first, not the other way around.
So it's finding the largest non-contiguous combo from sets where the second number is higher than the first.
 
Yes. I don't know that the leetcode problem will be solved with Kadane.
You need to find the biggest difference not the biggest sum.
 
6:42 PM
Is there a set of algorithms to choose from that are within a high probability of relevance to your typical problem?
 
10 --> 100 yeilds a bigger profit than 80 ---> 90, but the latter has a greater sum
@Matthew With regards to interviews, I think there is. But for real application, which interviews fail to replicate for some reason, I don't think so.
I've never taken a true coding interview (I'm only 17) but maybe some of the others in this room can provide more on that subject
P.S. This room is more popular on weekdays, so you may want to reask then.
 
tnx
 
np
 
LeetCode has mock interviews which I'll do soon. I have a friend at Google who recommended LeetCode, his background wasn't even coding, but EE for hardware.
 
LeetCode is definitively a good resource.
 
6:49 PM
What helped you improve your workflow or approach to problem solving?
 
Solving problems :D
 
haha. Makes sense. I hope by the end of the month I'll have done 30 on LeetCode and at least be a little quicker.
 
Let me just offer some advice. LeetCode is great for interview questions, but once you have the job you will almost never use the stuff on LeetCode.
I suggest having at least 50% (but probably more) of your practice in practical real life projects.
 
Tnx. Another friend of mine who worked at Capital One told me to do projects. These are the two areas I'm trying to focus on now, interview/portfolio.
 
By "solving problems" I mean, having the idea to build application X, and figuring out how to build X.
Being able to break a large project into smaller ones and solving them
Those types of skills will allow you to keep the job once you get it :)
 
6:53 PM
That's definitely my concern, staying in, not simply getting in.
 
Good luck with your interview!
 
Tnx.
Here in the DMV area, there's a surge of Java jobs.
 
Probably because no one wants to work with Java ;)
 
But it looks like JavaScript and Python are at the top now.
haha
 
 
2 hours later…
9:21 PM
i think i over flex
i seem to use it on just about every div
 
display: flex; ?
 
yep
It works well, has good browser support, and it seems to be maintainable so i don't see why not
 
9:36 PM
 
9:46 PM
I use flexbox all the time, but I believe starting with grid might be the ideal.
wow, that is a great codepen
If I update the local_value on every iteration, only changing the global_value when it is less than the current_value, how do I assign the current value with...
every possible combination, from left to right
I'm not merely trying to compare first and second, then second and third, but ... somehow non-contiuous.
contiguous
 
@Matthew Grid? Grid design is like web 1990s.
@Matthew code example
 
I mean CSS grid, came out in maybe 2016 I think
 
oh i'm thinking of tables
 
I'm watching a guy explain it, I'll try to have a code example soon.
ideally, it seems like you can set up your entire site in the grid, then work within it to use flexbox, multicolumn, etc.
var maxProfit = function(prices) {

 let max = 0;
 let min = Integer.MAX_VALUE;

 for(let i = 0; i < prices.length; i++) {
     if(prices[i] < min) {
         min = prices[i];
     } else {
         max = Math.max(max, prices[i] - min);
     }
 }

 return max;

};
Integer.MAX_VALUE is Java, I need to change it to JS
Number.MAXVALUE maybe
yeah, that worked
 
10:08 PM
i hate that pattern
 
What would you recommend as an alternative?
 
 let min = prices[0];
but i hate that too
what if prices has no values
 
there will always be an array of share prices
 
what does this function even do?
 
meh, just use the maxvalue, still hate it tho
 
10:10 PM
finds the greatest possible buy and sell combination
 
so, you want to find both min and max?
 
@Matthew use a foreach loop, you don't use the index
 
I would just go for a for and a min = arr[0], max = arr[0]
 
^ yes but again, if there are no prices in that array that throws
 
if (arr.isEmpty())
    return null
let min = arr[0]
let max = min
loop, updating min and max
return {min=min, max=max}
 
10:12 PM
Yes, but you are wasting cpu cycles with an extra if ;)
 
you are wasting cpy cycles using JS
better write stuff in assembly
 
true true
 
Is there a name for this algorithm?
not Kadane, right?
my main concern is having to learn and relearn these
i'm looking for the equivalent of design patterns in algorithms
 
Hmm. I wouldn't focus on memorizing algorithms. Instead, learn to create your own. They will likely not be the best or most efficient. But thats not expected of you. As you pointed out Kadane was statistician. He spent his life algorithms and math. You can't be expected to do that in an hour interview.
 
copied from normal find-min, find-max functions
normally, I wouldnt even write stuff like that
but considering js doesnt have a function that does both, and you dont want to loop twice... this is a fine use case to get the min and max
in a more modern environment, you could set up a data stream from the array, have a min listener and a max listener on it and then process the stream, receiving the min and max
 
10:37 PM
tnx. Kadane may still be alive at Carnegie Mellon, 79 I think haha
 
11:05 PM
@Wietlol this isn't java
 
Java cant do that nicely tho
 
Yeah, doesn't it have the entire toStream thing?
 

« first day (3459 days earlier)      last day (1472 days later) »