« first day (3458 days earlier)      last day (1473 days later) » 

4:54 AM
hi
I have a question about extending classes
anyone here
 
 
2 hours later…
6:54 AM
hi
how can i seperate the seleted value outside the select box
 
 
3 hours later…
9:46 AM
I'm reading about sync and async programming. Do callback functions imply asynchronous programming?
There's this function loadImage
image = loadImage('some_url')
image.width // returns 0, since I think Image hasn't loaded yet

loadIMage('some_url', funtion(image) {
  console.log(image.width) // returns actual wicth
}
The loadImage function would be asynchronous?
 
 
4 hours later…
1:30 PM
Cna anyone please help me ?
1
Q: How can I color a city in open street map based on longitude and latitude?

SagorI am using open street map to show map in my application. The following code is used to show the open street map. <div id="map" style="width: 90%; height: 420px"></div> I am using the leaflet library to show the map. function drawMap() { var mapOptions = { ...

 
 
4 hours later…
5:39 PM
 
6:23 PM
i'm getting fed up with this
All I want is to create a typescript, react, mobx project
why is this so complicated!!!!!
 
 
1 hour later…
7:33 PM
Is there a simple way to iterate over an array and remove every element that satisfies a condition in the original array, and return that array?
 
@Matthew 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.
 
|| mdn filter
 
@Matthew ^
 
When I use filter it returns a new array with the items removed. I'm trying to change the original array and return it.
 
7:36 PM
||> let arr = [2,9,16,30,5]; arr = arr.filter(num => num > 10); console.log(arr)
 
@JBis undefined Logged: [16,30]
 
@Matthew ^
or go through it manually
 
"Note: filter() does not change the original array." w3schools.com/jsref/jsref_filter.asp
 
@Matthew w3schools is a terrible resource. We suggest using MDN. Here's an potentially equivalent page: Array.prototype.filter() - JavaScript | MDN
 
Again, you can simply use a for loop and manually remove them. It won't be functional but it will work.
 
7:39 PM
That's my issue. I want to use a for loop or map/forEach on an array, but am not sure what code to use to delete each element that meets a condition.
 
ah
|| mdn splice
 
that will allow you to remove elements of an array
 
Do I need to identify the current element's index, then splice it using that?
 
hey there, I have a question about React styling
I have a specific design in my styles const, which I'd like to use alongside a variable that defines the backgroundColor
 
7:41 PM
@Matthew Yes. That can be done with Array.indexOf or Array.findIndex depending on what you need to do.
 
is it possible to incorporate a styles.design and styling stored in a variable?
sorry im still new to react so i dont know all the vocabulary :/
 
Thanks
 
np
 
@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.
1 message moved to Trash can
1 message moved to Trash can
 
 
1 hour later…
8:55 PM
for(let i = 0; i < nums.length; i++){
     if(nums[i] == 0) {
         nums.indexOf(i) = j;
         nums.splice(j,1);
     }
}
@Matthew theres a bunch of issues with that
 
@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.
 
for(let i = 0; i < nums.length; i++) {
       if(nums[i] == 0) {
          nums.splice(i,1);
       }
    }
 
1 message moved to Trash can
 
@Matthew thats better
but its not going to work
||> const nums = [0,0,5,0,0]; for(let i = 0; i < nums.length; i++) {
       if(nums[i] == 0) {
          nums.splice(i,1);
       }
    }
 
@JBis [0] Logged: ``
@JBis 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.
 
8:58 PM
@Matthew you end up with an array with a in it
Any idea why? Think about what occurs when the item is removed at the end of the for loop.
 
Not sure. I failed the test case [0,0], returning [0,0,0]
I'm not sure what you mean by 'a' in it.
 
values:   [0, 0, 0, 0]
indices:   0  1  2  3
when you go around it looks like this:
    values:   [0, 0, 0, 0]
    indices:   0  1  2  3
    i: 0
    <--- removal -->
     values:   [0, 0, 0]
    indices:    0  1  2
    i: 0
   <---increment and start next iteration -->
    values:   [0, 0, 0]
    indices:   0  1  2
    i: 1
theres an issue now
i is 1, but we have zero'th index that isn't checked because the previous index was removed
@Matthew Does that concept make sense?
 
@Prasanth 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.
1 message moved to Trash can
 
hi all, i am frustrated with vscode showing me this big prompt covering all my code whenver i enter a new line in StyleSheet.create in react native.

Any way to nuke that prompt to never showup again?

image for reference as to what i am talking about:
https://i.imgur.com/hLTcZfI.png
 
@Prasanth 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.
For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
 
9:08 PM
@JBis, I wasn't thinking that the length of the array changed the moment I removed an element, making the second iteration take place on a smaller array.
 
You are mutating the original array, not creating a new one as intended.
An array cannot have two different sets of values in memory. That would be the equivalent of two real life objects taking the same space.
 
@JBis, is there a way to remove all elements that equal a certain condition in the original array without relying on the length of the shrinking array?
 
No. But there is a fix.
(I mean technically you could create your own class that extends array or use a proxy of some sort but thats beyond a terrible way of doing it)
Think about what I said:
 
@JBis my main issue is oblivion to intuitive solutions.
 
9 mins ago, by JBis
i is 1, but we have zero'th index that isn't checked because the previous index was removed
So i is 1, but we need it to be 0. How can we make i go from 0 to 1?
 
9:13 PM
@JBis can I remove elements after finding their location, but not depending on the array length?
 
@Matthew no, arrays use indices theres no way around that
 
@JBis
How about I don't increment the i++
So each removal simply operates on a shrinking array with the same i
 
closer but you still have an issue
if it doesn't increment and it doesn't meet the condition to be removed then you will keep checking the same index for ever
 
wow
 
Indeed, so instead of not incrementing, how can make it increment to the value we want?
Or in this case "undo" the increment
 
9:19 PM
i++, i-- ?
 
closer
 
but that's an infinite loop too?
 
yes
Under normal circumstances the loop will run fine, it is only because we are removing an element that it doesn't. So we only want to i-- under certain conditions, what are those conditions?
don't overthink it
 
it worked. I just put i-- at the end of the sequence
 for(let i = 0; i < nums.length; i++) {
       if(nums[i] == 0) {
          nums.splice(i,1);
          i--;
       }
    }
 
Yes, correct. Why does that work tho?
 
9:23 PM
thanks so much, that helped a lot. Because it resets 'i' after every iteration and then loops through the new length.
Is there ever an equivalent in the opposite direction, where you need to increase the 'i' to accommodate a larger array?
 
9:58 PM
@Matthew i guess if you are conditionally adding something to the middle of the array but i have never encountered that
@Matthew Yeah basically. You are conditionally "undo"ing i++ (because -1 + 1 = 0).
np
 
10:47 PM
this is really interesting
const x = {test: {str: "string"} };
const y = x.test;
delete x.test;
console.log(x); // {}
console.log(y); // { str: "string"}
 

« first day (3458 days earlier)      last day (1473 days later) »