Newest 'arrays' Questions - Stack Overflow

Questions tagged [arrays]

An array is an ordered 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 which is specific to a programming language, tag the question with the programming language being used.

0
votes
0answers
10 views

Get an element with its index counting from the end in Kotlin

Is there a simple function to get an element with its index counting from the end in a Kotlin Array, List, or String? In other words, is there a Kotlin equivalent of negative index slicing in Python?
0
votes
0answers
10 views

I'm unable to manipulate data stored in an array from firebase

I'm getting data from firebase with the following compound query: filterItineraries(filters: any): any { this.allItineraries = []; this.filteredItineraries = []; for ( let i = ...
0
votes
0answers
5 views

Splitting the state vector when solving a series of odes using python odeint scipy

I'm converting my code from Matlab to Python and stuck on how to split the state vector such that the result returns the two solution. I have a vector and a single value for the two initial conditions ...
-1
votes
2answers
28 views

How can I filter an array but with one excepcetion?

I am trying to filter an array so I am not sending any falsy values. const notFalsyItems = my_team.filter( ({ about, email, mobile, last_name, country_code_mobile }) => about && ...
0
votes
0answers
12 views

taking input from user to reverse an array by swapping

I'm new to kotlin..please help me in this code. I want to reverse an array by swapping the values..kindly help me with good lines of code and explain each line fun main(args:Array<String>) { ...
0
votes
1answer
20 views

Numpy array as element of pandas dataframe management

I'm considering a Pandas Dataframe. I would like to find an efficient way in which the second Dataframe is created every time the name of a column contains the number 4 and therefore column elements ...
0
votes
1answer
22 views

Load more list items using forEach

I have list that everytime i click on button load more itens of the list, but whent i use a loop to get a list from a array, the code don't work! .hideclass { position: absolute; overflow: ...
0
votes
1answer
25 views

Storing a instance/object in a array

I am creating a console zombie survival game that is suppose be random and be fairly complex, such as finding multiple weapons, and ammo types. However, I believe that I could save an object in array ...
-2
votes
1answer
35 views

Invert the values of a vector using the same vector and two indices

Given a number N (<30), and a vector VEC of N elements that contain integer values, invert the contents of the vector and report it using the same vector with two indices. I have no idea how to ...
0
votes
1answer
14 views

How can I call resolve in a promise while looping through an object that only meets certain conditions?

I have a function that contains a promise that contains a setTimeout function. The set timeout function loops through an axios call that spreads out calls to avoid a rate limit error. This works great,...
-2
votes
0answers
40 views

When less then max number of integers is inputted, code does not run

For the program, I know that the maximum amount of integers that can be inputted is 100 but they could also enter 2 integers or 3 or so on. but if I enter less then 100 the program just stays waiting ...
0
votes
2answers
15 views

AngularJS ng-repeat and indexOf() to check objects

I have two json objects (data1 and data2) that have related information. Namely, both objects have properties (arrays) which in turn can have identical data. So, I am trying to figure out how to ...
0
votes
0answers
4 views

BBC Basic Add an array to another array

I'm trying to add an array to an array mainly using ARRAYLIB. Nothing I have done so far has worked INSTALL @lib$ + "ARRAYLIB" DIM ARRAY1(0) DIM ARRAY2(3) LET ARRAY2() = 1, 2, 3, 4 ARRAY1 is the ...
-2
votes
3answers
25 views

filtering a 2D array in javascript, i tried everything

I have 2D array like this : [[ONE,1],[QUARTER,0.25],[QUARTER,0.25]] I want it to become : [[ONE,1],[QUARTER,0.5]] I tried using array.IndexOf but no luck ONE,1,QUARTER,0.25,QUARTER,0.25
0
votes
0answers
21 views

Blank array behaving strangely when filling it with values depending on how it was created (Ruby)

I've got an array of arrays where it's filled iteratively, but for some reason, it seems like how it was defined is changing its behaviour even when its result is equal to that of the other method. So ...
0
votes
1answer
24 views

How to Merge two or more multidimensional arrays into single multidimensional array using Java

I need to merge my four 3D arrays into single 3D array in java, Object[][][] obj1,obj2,obj3,obj4; obj1 = new Object[7][8][7]; obj2 = new Object[7][8][7]; obj3 = new Object[7][8][7]; obj4 = new Object[...
0
votes
1answer
28 views

Nested Arrays inside an object, searching with For loop, giving undefined result

I keep getting "results.picks[i] is undefined" in this loop, but it works when I take it out of context and simplify it. Does anyone know what is wrong? function getdraws() { var results = new ...
0
votes
3answers
37 views

Backwards loop only printing undefined

I am attempting to create a function that can take in an array and display its contents backwards. I am having trouble with understanding why my function call is showing undefined when I enter an ...
2
votes
0answers
21 views

Rank and unrank Combination with constraints

I want to rank and unrank combinations with an Element distance constraint. Selected elements cannot repeated. For example: n := 10 elements choose from k := 5 elements being choosen d := 3 max ...
-5
votes
1answer
29 views

How to use JSON data to create an array

Okay so I want to be able to take a JSON file (external) and process it so that I can create an array that I can use to display the data. JSON.parse() only works if I declare the JSON array then ...
0
votes
1answer
19 views

How to create list of unique array items from thousands of records in Rails?

I have an Artist model with a genres jsonb column that has data like this: > Artist.first.genres =>["alternative emo", "anthem emo", "dreamo", "emo", "neon pop punk", "pop emo", "pop punk"] &...
0
votes
0answers
16 views

How to Convert String in a Text File into Array in Bash

I have text file containing quotes inside single quotes. They are "not" one liners. eg there may be two quotes in same line, but all quotes are inside single quotes like 'hello world' 'this is the ...
-1
votes
1answer
18 views

How to append key values to JSON file properly (without creating extra structure)?

I want to create JSON file in Python, which stores X and Y values. It should look for example like this: {"X": [[1,2,3], [2,3,5], [1,2,6], [1,2,3], [2,3,5], [1,2,6]],"Y": [3,5,1,3,5,1]} This is ...
-2
votes
3answers
58 views

Why doesn't the for loop increment?

Why doesn't my for-loop increment? The Integer "i" doesn't increment somehow and that results the first position of the array to be printed out. I do the following: int* values = new int[10] {}; ...
0
votes
1answer
38 views

Reformat php array - json

I have a php array that outputs a json like this: "extraDetails":[ { "basic":{ "0":{ "id":"101" }, "1":{ "details":"176381954" }, "16":{ "birth_date":"1\/15\/1973" } ] There are multiple headings ...
0
votes
1answer
51 views

Is there any chance in Python3 to create a matrix of arrays of arrays?

Let's start by saying that I am a very beginner in Python so maybe my question is more stupid than I think. What I would like to do is the following Create a matrix At position [i,j] of this matrix,...
0
votes
3answers
29 views

Generating and Looping through random numbers array with Next button

So I have this JS array variable with string values. This generates quotes at each button click. I noticed that after going through all quotes, there's one last click that outputs nothing. So I have ...
2
votes
2answers
21 views

How to print out the specific item of an array using .addEventListener?

I'm creating a sort of tic tac toe game. I have a grid mapped out in .html, and I'm trying to get the each box to say "You clicked 'box location'" when pressed. The element id's are labeled from 0-8....
1
vote
1answer
36 views

How can I average multiple arrays assigned to one variable?

I'm trying to interpret a large data set into multiple smaller 128 by 128 arrays to later average together into one singular array of the same size. I've been able to create one very long array with ...
0
votes
2answers
35 views

Sorted Array one dimensional, but array[i+1] always print element at index zero

Hello i have a little question. I want sorted array one dimensional. here the code, public class MyClass { public static void main(String args[]) { String[] array = new String[]{"a","b","c","d","...
1
vote
3answers
44 views

How to map two arrays of objects, concatenate them, and add an index efficiently

I have two different arrays of objects that need to be mapped individually to key:value pairs defined by me. When mapping, each of the objects should be assigned a sequential index. Then, I need to ...
-1
votes
1answer
18 views

cmp instruction not making jge jump within InsertionSort

I am trying to write an iterative version of InsertionSort using MASM. After repeatedly getting unexpected errors, I tried running through the code line by line and watching in the debugger that it ...
0
votes
2answers
36 views

define array variable inside array

How to define variable inside array without key? This doesnt working and I dont know how... $array = array("list" => array()); $list = $array["list"][] = array("sub_list" = array()); $list["...
1
vote
2answers
32 views

Sort ruby hash of array and hashes

Is there any generic way to sort a Hash which is composed by any other hashes and arrays? I have tagindex = Hash.new() which has hashes and arrays into: tagindex['keywords'] is a hash and tagindex['...
2
votes
1answer
28 views

Flatten nested array with type inference

I am trying to create a function that can flatten nested arrays in typescript. So far I have this: function flattenArrayByKey<T, TProp extends keyof T>(array: T[], prop: TProp): T[TProp] { ...
0
votes
0answers
27 views

how to replace a node with the same node obtained by a fetch with javascript es6

I have two Arrays and i would like to replace each node with its new corresponding node let filters = doucment.querySelectorAll('.js-filter') filters.forEach((filter) => { filter....
0
votes
1answer
24 views

In an array of hashes, how to count the list of 'webpages' with most unique 'page' views?

I have a text file which contains how many times a specific page has been visited by an IP, example: /help_page/1 126.318.035.038 /contact 184.123.665.067 /home 184.123.665.067 /about/2 444.701.448....
-1
votes
0answers
29 views

Is there an easier way to Check a Variable Value - if it matches a list of values output a corresponding value [duplicate]

I have list of Values - 45 Rows: Finance:David Bowie Security:John Denver Human Resources:Dennis Hopper Maintenance:Steve Glover Information Services:Danny Elfman I would like to be able to ...
1
vote
2answers
22 views

Replace specified text from index to another index in array python

I want to replace a searched text in an array from a specified element to another specified element in this array. I know there is a “replace” function but it will replace all the occurrences of that ...
1
vote
3answers
59 views

How to find specific number in a string php?

I have different strings in which I want to find specific number. If the number is within the string it should print that number. Strings are like these: string(9) "path_12.0" string(9) "path_12.1" ...
1
vote
0answers
21 views

Javascript - how to access the result within readfile close event and return it to initial function

I am using readline to read a text file line-by-line and process it with some filtering. The text file contains lots of abbreviations and the corresponding whole word or sentence. For example "BTW" ...
0
votes
2answers
23 views

How to get number of instances of a string in Json object using javascript

I've below Json object that contain car associated to their manufacturer. From Json object, I want to get total number of cars as well as occurrence of a specific car in the object. `var Cars = {"...
-2
votes
3answers
46 views

please explain the ouptput of following code

i have been trying to insert a new element into a given array at a given index. though i am able to insert new element but i have few doubts.. why it got inserted at 7th index instead at 3? how value ...
-1
votes
1answer
57 views

How do I return an array?

I need to write an app that takes the string that is entered into a text field and use it to call a thesaurus function. The function must return an array that contains synonyms to the string, but I ...
0
votes
1answer
27 views

How to remove all elements from sorted Ruby array which are closer to its closest neighbour than a limit?

I have a sorted array of real numbers in my Ruby program. I want to remove all the elements which are very "similar": their difference is smaller then a given limit. So finally I want to keep only ...
0
votes
2answers
32 views

Trouble casting integer object to primitive type

I'm trying to do this challenge on codewars : https://www.codewars.com/kata/554ca54ffa7d91b236000023/train/java I changed the original array into an arraylist, but then I have to use the values in ...
-2
votes
1answer
54 views

JS length is shorter than number of elements

I have a JS array that has length 20, but .length, a forEach, and a for loop all say basically 11. Some ways I tried to calc it (began with .length): console.log('data length: ' + data.length); ...
0
votes
1answer
27 views

Implode php array

I have an array like this: $Array = [ [1, 33, 55, 18], [8, 9, 12, 67], [3, 33, 76, 88], ]; And I want add ; to output like this: 1, 33, 55, 18; 8, 9, 12, 67; 3, 33, 76, 88 ...
1
vote
1answer
14 views

How do I add ESNext Array functions to an existing nested array interface?

I'm getting this error: TS2339: Property 'flat' does not exist on type 'ContentfulImageAsset[][]'. I want to add .flat() to ContentfulImageAsset[][]. I tried adding it to my interface and got: ...
0
votes
0answers
37 views

How to append to the DOM only once inside of ajax polling method

I am slowly stepping away from using jQuery for every single situation, by only using it where necessary, while using the ES6 syntax. I have some code which sends an AJAX reqeust every x seconds. I ...