All Questions
Tagged with array javascript
15 questions
0
votes
1
answer
541
views
Array structure for nested grouping (JavaScript)
I am currently struggling with how to solve nested grouping of data.
The initial structure is given and my grouped structure below as well as my approach can be adjusted.
My idea was to have the array ...
0
votes
0
answers
57
views
JavaScript: My logic traversing multi-dimensional arrays
Consider the following:
Let's say below is the multi-dimensional, and you are given the starting point of [2, 2].
const WORLD = [
['P', 'P', 'P', 'C', 'P'],
['P', 'M', 'P', 'C', 'P'],
...
2
votes
2
answers
2k
views
JS - two array filters vs. one forEach?
I've had a question for a while. I know that the Array prototype method filter is generally preferred over forEach, and I believe it is typically faster at the job as well.
But what about if I have ...
4
votes
2
answers
1k
views
Arrays vs Maps for listing items that have a unique id
I've been finding that for a lot of code I've been writing recently, it naively might look like this:
Array approach:
const options = [
{
id: 'red',
label: 'Red',
data: '#f00'
...
3
votes
1
answer
400
views
What is the expected performance of While loops using `array.pop()` assignment vs other methods
Recently I was asked to refactor some code that leverages JavaScript's array.reduce() method because other developers felt the code hard to read. While doing this I decided to play around with some ...
2
votes
1
answer
2k
views
How should I define hardcoded strings with some variable parts? Reuse more characters? Or keep the whole sentence?
for example, sometimes I need to define a hardcoded string with some variable parts, I often have trouble to choose the style:
style 1 : reuse every characters when possible
showMessage(num){
let ...
2
votes
2
answers
509
views
Should I use Array or Set if both can be used to finish my task?
for example, Suppose I have a 2d array:
let filterArr=[
[1,1,0,1,1],
[0,1,1,1,0],
[1,1,0,1,0]
];
I want to find and store the index of column that all are 1, i.e.:position 1 and 3, and the ...
-1
votes
2
answers
1k
views
How does a dynamic array access work?
In C if i declare
int x[4]
Which tells me its an integer array with each array element size fixed of size 4.
So after initialization when I access x[3] : address of array +element size which is 2 * ...
2
votes
1
answer
2k
views
Should objects be singular since arrays are plural?
Might be a silly question, but what is more logical:
object.actions.bark() or object.action.bark()?
Simply about plurality. I know arrays are usually pluralized. But if I were to be consistent; ...
9
votes
2
answers
11k
views
Is it good practice to use array.pop() assignment in a while loop condition?
Just saw a code snippet that used an array pop assignment in the while condition; was wondering if this is acceptable/good practice?
var arr = [0,1,2,3,4,5];
var current;
while (current = arr.pop())
{...
-5
votes
1
answer
2k
views
How to compare and replace value from two object inside array?
Here i want to replace price in data1 to price from data2, and it updated if the id is same.
Is it possible to do that without nested loop?
var data1 = [{
"id": "56e641d4864e5b780bb992c6",
...
6
votes
1
answer
2k
views
Why is Array.prototype designed to be a fully functional array?
In the below visualisation,
There are two array objects(cars & bikes) that are created with below syntax,
var cars = new Array("Saab", "Volvo", "BMW");
var bikes = ["Honda", "Yamaha"];
whose [[...
1
vote
0
answers
463
views
Why is deep plucking a bad idea?
Both underscore and lodash refuse to implement deep plucking, despite many requests from users and gists or modules that implement the feature.
_([{o:{a:1}},{o:{a:43}},{o:{a:234}},{o:{a:23}}]).pluck("...
2
votes
2
answers
3k
views
Why a hashtable? Why not just a non-hashed associative array?
I've been learning about using a hashtable to efficiently check for items in a list without looping through the whole thing, but there's one thing that I don't get:
Why hashed keys?
It seems like:
...
0
votes
2
answers
717
views
arrays format (Javascript)
I have a list of users, with minions, something like this:
User52:
minion10
minion12
User32:
minion13
minion11
I've been keeping in an array where the "location" is the id, ...