418,174 questions
-4
votes
1
answer
109
views
How should I efficiently add all pairs in a key-value array to an object?
I have an object obj; and I then obtain an array arr of key-value pairs. Assuming that the key sets of obj and of arr are disjoint (i.e. no key appears in both) - how do I efficiently add all pairs in ...
-6
votes
0
answers
117
views
How to bubble sort an array stored inside a class?
I have a simple class that contains a fixed size int array.
The class can initialize the array, shuffle it, and print it.
Here is the code (C++)
#include <iostream>
#include <algorithm>
#...
3
votes
2
answers
106
views
Code is returning "[C Kernel] Executable exited with code -11", don't know what's wrong with it?
I'm working on this piece of code as part of my coursework, ideally any advice I get for this would be educational in some way; I don't want an exact answer, just need someone who knows more than I do ...
-4
votes
0
answers
54
views
JavaScript filter() not working as expected - returns empty array with valid data [closed]
I'm filtering customer data to find duplicates based on email. My filter returns an empty array even though I know duplicates exist.
What am I doing wrong? How can I correctly find duplicate emails?
...
4
votes
4
answers
98
views
Map unknown associative array element
How can I map an unknown value alongside other known values in bash using an associative array, so that:
#!/bin/bash
array=("foo" "foo" "bar" "something else" &...
-3
votes
0
answers
75
views
This Codewars exercise is driving me up the wall [closed]
Okay, so I'm supposed to send Marty McFly back to the future, right? But it has to be on certain dates, using this function:
function backToTheFuture(str)
Here's my code:
function backToTheFuture(str) ...
0
votes
0
answers
81
views
Checking set in Poker [closed]
I am trying to simulate a deck of cards that can be shuffled, create a hand of 15, then check the hand to see if there is three of a kind within it.
I've added the code I have so far used to create ...
3
votes
2
answers
51
views
I'm getting an 'index out of bounds' error using solve_ivp
I'm trying to find the outbreak time (when the number of zombies >= number of humans) as a function of the zombification rate gamma, using the following code:
arrOutbreakT = []
arrGamma = np....
-5
votes
2
answers
127
views
Text file with JSON data became corrupted
This is my code
$serverGuestFile = fopen($_SERVER['DOCUMENT_ROOT'] . '/server/guest.txt', "r");
$serverGuestFileData = fread($serverGuestFile,filesize($_SERVER['DOCUMENT_ROOT'] . '/server/...
0
votes
0
answers
42
views
How to get foreach from file get contents php array url [duplicate]
I created a php array file.
My PHP Array File Example.
I put array to g.horje.com/t.php
<?php
$val = array (
0 =>
array (
0 => '1',
'id' => '1',
1 => 'Search Engine ...
Advice
0
votes
3
replies
95
views
Java : getting sorted order of Objects
I have an List of Objects that implements the Comparable Interface that I want to sort. I do not want the original List returned sorted, nor do I want an new List returned in sorted order. What I ...
Advice
0
votes
5
replies
84
views
How to assign unique elements to different indices?
I've been working on a program that prints out each word, their number of occurrence's and percentage of the number occurrences over total length of the sentence.
As you can imagine I had to create a ...
Advice
2
votes
3
replies
110
views
How do you use set() on PHP arrays?
When using setters/getters on arrays, does your set() override the entire array or just the key? What is the accepted or best practice for this?
Would you use set() for something like this or would ...
-3
votes
0
answers
51
views
How to decode JSON objet Python [closed]
I begin with Python.
I use this API https://docs.balldontlie.io/?python#get-all-teams
So my actual script is
import json
import pandas as pd
from balldontlie import BalldontlieAPI
api = ...
1
vote
1
answer
132
views
Why can't I return type byte in lambda expression in Arrays.setAll
I'm trying to implement a lambda function (for educational purposes) to initiate an array to append to the front of potentially encrypted data to save information like salt and initiation vector, ...
0
votes
2
answers
155
views
Updating stateful list in React based on another stateful variable
Here are two React components:
function MainScreen() {
const [stopwatches, setStopwatches] = useState([
new Stopwatch('A'),
new Stopwatch('B')
]);
const [selectedStopwatchIndex, ...
1
vote
1
answer
56
views
Array Reverse Proof by Dafny
Regarding the array reversal problem, I guess loop invariants are logically correct, based on the symmetry of the elements in the array and their relationship after reversal.
However, I don’t ...
1
vote
2
answers
59
views
How can I loop over an XML structure using Coldfusion
I'm trying to loop over an XML file and output the structure. However, I'm only getting one set of data on the second loop. Below is my code, and below that is a snippet of the XML structure.
<...
Advice
1
vote
14
replies
232
views
Ordered array vs. hash map in c++ (100 elements)
I need help regarding a code I want to write in c++.
I want to develop a program that receives and visualizes CAN messages on a GUI. The messages in question are about 100 distinct ID's, so we're not ...
4
votes
3
answers
164
views
Why does my C code display the correct output, but with garbage characters added after?
The practice question I am working on reads as:
Read two strings, both of them do not contain white spaces (but may contain non-alphanumeric, such as ‘,’, ‘.’, ‘/’ ...).
Display the first string ...
1
vote
1
answer
137
views
What am I doing wrong with my SAFEARRAYs?
I'm setting my first steps in COM communication. I have an application, written in C#, using a byte array, and that is working fine.
When I try to do the exact same thing in C++, it does not work.
I ...
1
vote
1
answer
61
views
query an array to a R {plumber2} API
The {plumber2} R package recently got released and I'm trying to understand how to leverage an API.
This basic example below works as long as I'm passing only one string without comma in my query.
#* ...
0
votes
0
answers
111
views
ClassCastException when comparing elements in custom ArrayOrderedList using Comparator
I am implementing an ordered list that automatically inserts elements in the correct sorted position using a Comparator. The list is built from scratch (not using java.util.ArrayList) and uses an ...
Advice
1
vote
9
replies
198
views
Is this array subscripting behavior really undefined in C?
unsigned int n = 1;
char* s = "X" + 1;
s[-n];
Is that third statement undefined in C23? It seems it is, as by the standard in 6.5.2.1.2:
... The definition of the subscript operator [] is ...
-5
votes
1
answer
135
views
Why is this C++ program giving a "Segmentation Error" on line 84? [closed]
I'm doing an assignment for an engineering course I'm taking, and I'm testing my code as I go along. For some reason, it gives an error when I compare an array element to a value passed into my ...
2
votes
1
answer
55
views
Edit Array issue with array of enums in Dymola
When editing an array of enumeration with unknown size in Dymola (2025x r1), it is possible for the user to set a value to the array which is not a vector:
type Catalogue = enumeration(A "A",...
Advice
1
vote
4
replies
92
views
Acyclic shifting of arrays (`eoshift`) in Julia
Circular shifting cshift in fortran as an equivalent in Julia : circshift. But I'am seeking an equivalent of eoshift (https://fortranwiki.org/fortran/show/eoshift) which is a acyclic shifting that ...
2
votes
2
answers
177
views
how to get PowerShell to gracefully accept a multi line, array, system.object input to a `[string]` parameter?
ff
I have a function foo, it needs to accept a string, this string can be passed to it directly by typing at the terminal, from a variable or from the clipboard.
function foo{
[CmdletBinding()]
...
1
vote
2
answers
141
views
How to set int array pointer within for loop in c
The following code is trying to set the test array in the first for loop, but it can't be used in the second for loop.
int main()
{
int *test[3];
/** Try to set the array value one by ...
0
votes
0
answers
24
views
How Can I Use String of Coordinates Within a Mapbox Feature?
I am trying to fetch a comma separated list of coordinates from a database and then show them on a Mapbox GL JS map.
By using the following FeatureCollection, I am able to show a Line between ...
0
votes
1
answer
42
views
Why does the use of "enlist" in the cross-sectional engine sometimes result in errors and sometimes work normally?
I am using the cross-sectional engine and need to store multiple rows of fields as a single array vector. However, I have encountered several issues during the process:
The scenarios I attempted are ...
3
votes
1
answer
139
views
How to convert a string in an array to variable using the array index in PHP [duplicate]
Let's say I have an array_1 containing a string which is a name of another array_2. And now I would like to convert the array index into a variable containing the array_2.
I have the following working ...
0
votes
3
answers
139
views
Array Functions
I am currently learning the new array functions in Excel. I've been learning them for a bit, but still learning.
I am trying to create a dynamic YTD type report off some dummy data however I can't ...
0
votes
3
answers
129
views
Workaround for #spill! in Excel when creating random integer array of random size (with constraints)?
How to construct a random size, random integer array with (exact) target sum value with a single Excel function (or 'best' viable/working solution given the 'known' volatile issue with this sort of ...
2
votes
2
answers
132
views
How do you use an array formula to count the number of times SO FAR a value appears in the array up to where the value is in the array?
I'm trying to use an array formula in Google Sheets in order to get how many times so far in an array a value has appeared. Specifically, I'm using an "array" of single upper case letters (...
4
votes
0
answers
401
views
Why does a simple C++ const array loop break GCC 11.2 assembly output on Compiler Explorer, but not GCC 15 or MSVC/ICX?
I've been investigating the assembly output for a simple C++ loop involving a const array and const size, and I've encountered peculiar version-specific behavior with GCC on Compiler Explorer.
My ...
7
votes
6
answers
2k
views
C program: Use an array outside the scope it was defined in
I have some code in which an array of strings is defined in a conditional statement. The array is out of scope where I need it. So I defined another pointer in the outer scope. In the conditional ...
2
votes
0
answers
166
views
How can I disable / warn on std::array::operator[] for some specializations of my type that can implicitly convert to a builtin integral type?
For background, I'm building a library (that is allowed to use C++23 in its interface and implementation), and as part of its underlying building blocks, I've defined a bounded integer abstraction ...
-4
votes
1
answer
114
views
NumPy high-dimensional array automatically rearranges after subsetting
Today I wanted to use the following command to subset a numpy high-dimensional array, but was surprised to find that the two methods were completely different. I'm very curious why numpy reorders the ...
3
votes
3
answers
188
views
Swapping corresponding negative and positive elements in an array while keeping constant order in their respective groups
The problem:
Given an array in which the number of negative elements is equal to the number of positive elements (arranged in arbitrary order). Swap the first negative and the first positive, then ...
1
vote
2
answers
105
views
Typescript sort array of array tuples
I have tuples in the form (Status and priority)
[State,prio]
States are defined so:
enum State {
A = "A",
B = "B",
C = "C"
...
}
Now i want to sort an ...
1
vote
1
answer
161
views
Why does IRB display arrays differently depending on their length?
I am currently experimenting with arrays in irb.
If my array has 22 elements, it will display properly as shown below: (Screenshot)
#Ruby Version 3.4.7
x = 1..22
#=> 1..22
x.to_a
#=> [1, 2, 3, ...
2
votes
2
answers
153
views
Convert from iferror vlookup to VBA's dictionary array
I need help with a repetitive task that I use vlookup for huge dataset, a bunch of tables of >1 million rows from multiple columns, multiple sheets of another workbook.
ID
TA
ISRC
Result
ID1
TA1
...
3
votes
1
answer
162
views
How can i optimize my brute force solution with O(n²) time complexity?
I am currently solving the Container with most water, it actually works fine with both cases, but once I submit it, I get TLE which I believe is because my approach is O(n²) and it clearly says on the ...
0
votes
1
answer
58
views
WordPress RestAPI in Javascript. How to get array data out of the response
I am working on a Gutenberg block and am modifying the Edit.js file. I want to fetch the root categories in the database. From the reading I have done, it seems a good way to do this is to use the ...
1
vote
2
answers
95
views
Is there a bug in the method below (Data Structures & Algorithms by Robert Lafore)
The method below has been taken from the book Data Structures & Algorithms by Robert Lafore. This method is used to bubble sort a given array. nElems is the number of elements in the array. In my ...
0
votes
1
answer
60
views
Using embedded youtube playlist index to cycle through array
I have a youtube playlist embedded in an iframe and was hoping to use the playlist index to cycle through an array of titles on-screen (i.e. when the next video starts playing, the next item in the ...
-2
votes
1
answer
181
views
The algorithm to create the target array from an array of randomly inputted characters [closed]
I've been working on a function that takes a string of random characters as parameter (char *scrap) and forms a meaningful sentence or a name out of it by matching it with letters from another string (...
1
vote
0
answers
206
views
C# array[i] where i is IBinaryInteger<T>?
A BinaryInteger<T> is an integer of some bit-length. I'd like to use it to index an array.
Casting to an int isn't possible - I have to use int.CreateTruncating(i) (or similar) at run-time to ...
1
vote
2
answers
110
views
Get previous and next row of a matched row from a 2d array
I have the following code to sort the items based on a timestamp.
$arr = [];
foreach(glob('*.json') AS $item) {
$data = json_decode(file_get_contents($item), true);
$arr[] = [
'taken' =...