Questions tagged [arrays]
An array is an ordered linear data structure consisting of a collection of elements (values, variables, or references), each identified by one or more indexes. When asking about specific variants of arrays, use these related tags instead: [vector], [arraylist], [matrix]. When using this tag, in a question that is specific to a programming language, tag the question with the programming language being used.
arrays
417,309
questions
0
votes
1
answer
15
views
Detect array type in source generator
I'm writing a source generator that processes my model classes and adds some custom serialisation code for them. The model classes can have all sorts of property types. I'm currently interested in the ...
0
votes
0
answers
47
views
Using arrays from different classes in java
I am making a TicTacToe game. The idea is I print a 3x3 grid with numbers from 1-9 and when a player selects a number it changes that element in the grid array with a character like * or o
I'm facing ...
0
votes
1
answer
93
views
Smallest element after xor
Starting with array of N positive integers, support Q queries. Each query contains a positive integer i. To answer the query, replace each element of the array with the result of xoring it with i, ...
0
votes
1
answer
29
views
set array items into separate variables
I am trying to set each item in an array into their own variables. Here is what the array looks like:
labels = ["label1", "label2", "label3", "label4", "...
0
votes
1
answer
11
views
i want to create a modal, when i click on button having id a modal should be opened having card
i have created a courses page and create a fullscreen which should be opened when button is clicked modal is also opened but i am having an error in JS.
let value = colc[details.target.id]
if(details....
0
votes
1
answer
27
views
Have my array be split and added on to the new array, instead of completely restarting it each loop
I have a problem with my array. Each loop, the array gets cleared and new values gets added onto it. How could I make it so as the array gets filtered, it gets added to a new array to fill it up with ...
1
vote
2
answers
36
views
HTML audio with javascript: playback of playlist is not correct -> index 2 is always skipped
Need someone to help me understand, why index 2 of the playlist array that is passed to the audio element is skipped - no matter what. This is the console output:
0: /track01.mp3
1: /track02.mp3
2: /...
0
votes
0
answers
31
views
How to find all points that satisfy the Gas Station (Leetcode) problem?
I want to solve a similar problem to the https://leetcode.com/problems/gas-station/description/ problem:
given n gas stations on a circular route, the ith station has g[i] gas. the cost to travel from ...
0
votes
1
answer
48
views
Powershell : Compare an Hashtable to multiple System.Object and return only the matching one
I'm trying to compare an hashtable to multiple output from Pipeline, in he shortest way ( one line if possible).
Each output will contains at minimum same Property as Key in hashtable, but could have ...
-3
votes
0
answers
32
views
cannot reshape array of size 1000 into shape (100,100) [closed]
>>> cent_rand = np.random.randint(1919, 3946, 1000)
>>> len(cent_rand)
1000
>>> two_d_cent = cent_rand.reshape((100,100))
Traceback (most recent call last):
File "<...
0
votes
0
answers
30
views
Calling methods from array of method pointers not executing [duplicate]
This doesn't execute any suggestions:
void (CClient::*pMethod[CNetwork::ClientEvent::E_CE_MAX_EVENTS])();
pMethod[CNetwork::ClientEvent::E_CE_ACCEPTED] = &CClient::Accepted;
pMethod[CNetwork::...
0
votes
1
answer
53
views
GoLang - looping through array of structs - can I map?
I'm new to GoLang, coming from Node. A little late to the (definitely not functional) game and need some help understanding approaches, and perhaps just understanding...
I want to omit an item from a ...
0
votes
1
answer
14
views
How to pass CoreStoreObjects to SwiftUI - potentially using Combine or RxSwift [closed]
I have been implementing CoreStore after previously using SwiftData. I have inserts and predicates working, but I have not succeeded at displaying any data in a view. One complication is that each ...
0
votes
0
answers
35
views
Powershell array of strings into single sql column
I've this array of strings:
$qLastSS_T
2024-07-08 11:56:32
2024-08-08 12:56:32
2024-09-08 13:56:32
2024-10-08 13:56:32
2024-11-08 15:56:32
2024-12-08 16:56:32
and a sql table like this:
It's ...
0
votes
0
answers
26
views
Ternary in an array, string PHP [closed]
array
(
'head' => "Birth and Early Years",
'text' => array
(
"Jason A. Cloud was on <a href=''>Bellona</a>, Prime Hospital, to <a href='...
0
votes
0
answers
27
views
I cannot run array function in excel (MS 365) to create a migration matrix [closed]
I am trying to implement migration risk calculation based on a moodys rating migration from 30 years. As a first step, I have this matrix as source;
Average one-year letter rating migration rates, ...
0
votes
0
answers
92
views
sizeof() operator in c++ displaying different results in case of arrays [duplicate]
Why is the result of the two array sizes are different?
#include <iostream>
using namespace std;
void fun(int a[]){
cout <<sizeof(a)/sizeof(int)<<" ";
cout<<...
0
votes
0
answers
42
views
Return the latest group of records inserted by specifically me into a table along with their ID in the table?
I have a table of Customers, named Customer with the following columns:
CustomerID
CustomerName
ContactNo
Address
DateCreated
1
Idola Steenson
438614198
Morena
2022-08-14 09:48:00
2
Graham Buckner
...
0
votes
2
answers
36
views
Utilizing array items as an entire case in a switch statement
I would like to generate cases in a switch statement from an array. Here is how the array is generated:
pointObjects = [];
for (var i = 0; i < 2; i++) {
// Generate cases.
var url;
var ...
-7
votes
0
answers
51
views
How To Access An Item In A Struct Which Is In An Array [closed]
I am making a tower defense game and used structs in an array and want to access an item in the structs. I don't want to use a 2d array as that can't show up in a unity editor.
I tried tutorials and ...
0
votes
2
answers
57
views
How to process this text?
I have a text file that contains these lines and I'm not exactly sure what's the best way to use Python to load into separate key:value pairs.
dummy-test-foo,rsa,4096,[DNS.1:dummy-test,DNS.2:dummy-...
-1
votes
1
answer
64
views
Why does this for loop run faster when it runs inside a helper function? [duplicate]
I was doing LC# 1002, I spent an hour to figure out why does runtime is lower from 3 ms to 1ms after I made this change. Their logic looks exactly the same to me.
3ms
// Update the count array ...
0
votes
0
answers
36
views
Typescript Json get value [duplicate]
I'm getting from api {"bmw":[{"year":2022, "color": "black", "perfs":{"bmw":{"model": "x5", "county": "...
-3
votes
2
answers
41
views
Uncaught ReferenceError: a is not defined on line: 10 [closed]
I am trying to solve this challenge.
Question
Given are two arrays a and b, both have three elements. Return a new array of length 2 containing both middle (index 1) elements of the arrays).
Error
...
-1
votes
0
answers
29
views
Mysql fetch array doesn't show results even if the query is correct [duplicate]
I create the connection, which is right
$servername = "localhost";
$username = "myuser";
$password = "mypass";
$db = "dbname"
$conn = mysqli_connect($...
1
vote
1
answer
22
views
React Native trying to use same array globally
I am trying to learn React Native and am wondering if there is a way to store an array, say in a constant file or something, and reuse it in different components. States will be one, as an example. I ...
-1
votes
1
answer
49
views
Go type assertion (any) [duplicate]
This seems likely to be a duplicate but I couldn't find a solution. Please point me in the right direction if it is a duplicate
I am relatively new to Go and here I am trying to create a helper ...
0
votes
1
answer
60
views
Why does my C program with any input results in segmentation fault?
I've spent hours of racking my brain on why doesn't this work
#include <stdio.h>
#define MAXLINE 1000
#define TRUE 1
#define FALSE 0
int getLine(char s[], int lim);
void copy(char to[], char ...
-1
votes
0
answers
55
views
How to get an object of value from dropdown menu instead of a string? [closed]
Running the code I have a string but I need an object. Any way to do that?
<!-- language: lang-html -->
<select name="plates" id="degrees">
<option ...
-1
votes
1
answer
32
views
Is there any design pattern or way in Javascript that can be used to display some of the fields in nested JSON array
Below is the nested array of objects that needs to be displayed as a table. Currently, map is used to loop through items to return another array of all the elements required to display.
{
"...
-1
votes
1
answer
63
views
array_filter() returning the entire array instead of just the key value [duplicate]
I am doing a work around with PHP array_filter() function. I am noticing a strange. Let me explain.
This is an array $languageDataArray:-
$languageDataArray = array(
array(
'id' => 1,
...
1
vote
0
answers
46
views
Copying differently contiguous arrays vs same contiguity arrays
I'm observing different speeds on different machines, but couldn't reason why. Please help me find the reason behind this and how one can handle this difference in performance-critical code - running ...
-2
votes
1
answer
55
views
Binding/Pass-By-Reference for Array from Struct to Struct
I have one struct, struct DropletsView: View {} which has the following array: @State private var savedQuotes: [Quote] = [] (Quote is defined elsewhere, as a custom type for my app).
I would like to ...
1
vote
5
answers
71
views
In C#, I'm trying to iterate strings in single loop, how?
I'm trying to achieve this output:
LOWEST LOW MEDIUM HIGH HIGHEST HIGHEST HIGH MEDIUM LOW LOWEST
I know there are many ways to do it, but I'm trying it in single loop, is it achievable?
My code is ...
-2
votes
1
answer
24
views
Find my value in a range of key-values in an array of objects
I need to find my value in a range of key-values in an array of objects. And then perform some math on the object that matches the criteria.
const array-of-objects = [
{w1: 0.1, w2 0.5, Jv1: ...
0
votes
1
answer
18
views
Is it possible to limit results from Svelte {#each} loop by a certain amount?
I'm using an {#each} loop to showcase data, but I'm curious if Svelte has a way to limit the results by an integer.
For example, if I had the following array and loop:
const object = [1, 2, 3, 4, 5];
...
0
votes
0
answers
28
views
unable to take input of strings from user [duplicate]
I have to make an array of structure for cricketers presenting their name, age etc. and take input of each value from user . I am trying to get value of name from the user but my code editor keeps on ...
2
votes
0
answers
32
views
Completely deleting elements from Matlab R2020b cell array
I have a Matlab R2020b cell array with <missing> values:
my_array =
6×1 cell array
{'a' }
{'b' }
{'c' }
{'d' }
{1×1 missing}
{1×1 missing}
...
1
vote
1
answer
43
views
Accessing variable name inside proc in tcl
I am trying to create a proc that lists all elements of an array:
Here is the proc:
proc array_values {array_input} {
upvar $array_input arr
foreach name [lsort [array names arr]] {puts "arr($...
0
votes
0
answers
18
views
Time Complexity of my Subset Sum Problem's Solution [duplicate]
class Solution {
public:
vector<vector<int>> subsetsRec(int i,vector<int>& nums) {
vector<vector<int>> ans;
if(i==0){
vector<int>...
-3
votes
0
answers
27
views
Repeated indexes in list - Python [duplicate]
I have a long list, that is read from .csv file and it goes like this:
frequency = [..., 398, 399, 398.8, 400, ...]
and so on...
I need to find index for each value, but if the frequency value ...
0
votes
1
answer
49
views
Excel data validation list from range specified in calculated cell
I have several columns with time values. With a Data Validation, I display a list that takes the values from a hidden column with a large range of time values. Depending on the value of another field, ...
-1
votes
1
answer
39
views
Array Index Out Of Bound Error for Finding an element in an infinite array by Kunal Kushwaha video
My Code
public class InfiniteElement{
public static void main(String[] args) {
int[] arr = {1, 2, 4, 6, 8, 9, 10 , 13, 16, 19, 20 ,23, 27, 40, 42, 44};
int target = 44;
...
0
votes
0
answers
54
views
Push entries into a result array from deepest nested loop, but also push an entry when deepest loop is not reached
I am creating an array for an order to then pass this data to stripe, the array has multiple forEach clauses.
The issue I am facing is, if the order item(s) does not have menu_options it is not ...
2
votes
3
answers
100
views
Do brackets have effect during array of pointers declaration?
Recently I was reading "The C programming language" text book by Brain and Dennis and encountered that there is a difference between the pointer array definitions shown below:
int (*a)[10];
...
-5
votes
1
answer
83
views
Union of two sorted arrays- GFG [closed]
vector<int> findUnion(int arr1[], int arr2[], int n, int m)
{
//Your code here
//return vector with correct order of elements
vector<int> temp;
int i=0;
...
2
votes
0
answers
52
views
How does a string unexpectedly become an array?
In one of my script I have the following problem: assigning to a string variable the result of a function makes the string an array. Example:
---------- (function edited for clarity)
$x=""
...
0
votes
0
answers
12
views
Mixed bracket types. Is this json or something else?
I am trying to parse data from a URL. I think it looks like json but I'm not sure. The URL also doesn't end in .json (something like https://google.com/file).
The format of the data on the page looks ...
-1
votes
1
answer
25
views
Why I receive an unknown variable error in my function?
I'm using AlgoBuild and inside the "input_vet()" function there's a while loop and in its condition I recall the variable N, which I assign a value in the main, and shows a unknown variable ...
0
votes
0
answers
36
views
How do I dynamically allocate memory for a multidimentional array in C? [duplicate]
Dynamically allocate memory for a multidimensional array (matrix) with a specified number of rows and columns.
How to allocate memory?
How to allocate memory for 2D array?
How to dynamically allocate ...