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.

Filter by
Sorted by
Tagged with
-1 votes
0 answers
12 views

How to modify original array in JS? [duplicate]

I have an array of objects like shown: var tutorials = [{_id: "1",code: "//"},{_id: "2",code: "//"}] I use the Array.prototype.find() method to find an object ...
  • 154
0 votes
0 answers
15 views

Last digit of fibonacci number program doesn't work properly for large numbers

This program executes properly for small numbers but doesn't execute properly for large numbers, for example when i entered the number 239, the result is -1 class FibonacciLastDigit { static long ...
-1 votes
0 answers
6 views

According to product inventory display the order no. that cannot be processed further

ABC company wants an order processing system for their order and inventory management. According to product inventory display the order no. that cannot be processed further. Also, Update the status of ...
-1 votes
1 answer
33 views

Array reading max as one more than input

**Warning: I am extremely new to coding. If this code looks like a mess, it's because it is. ** I had this code literally working perfectly... until my laptop restarted randomly and I lost all my code....
0 votes
2 answers
21 views

Char Arrays code in C Programming Book example not working

I'm working on Brian Kernighan and Dennis Ritchie's C Programming Language 2nd Edition, and the code provided on 1.9, on character arrays, isn't working for me. I'm sure it's not a problem with the ...
0 votes
0 answers
8 views

Mongodb aggregation combination - How To?

How to combine the following two aggregations in a way that the results of first aggregation is acted upon by the second aggregation? Aggregation #1: > [ > { > $group: { > _id: "...
  • 7
0 votes
0 answers
11 views

Vue2 with vuetify My Function works in adding all the values of checkbox but doesn't actually check the checkbox?

I'm working on a vue2 project with vuetify 1.5 and I'm having trouble displaying visually that the function CheckAll() is working. The actual functionality of CheckAll() adding the value objects into ...
0 votes
0 answers
9 views

Svelte: array writable store is not fully reactive

I'm rendering a chess board in svelte, and I've got the sliding pieces moving all right. To render the pieces I use a writable store(store_sqrValues): //Board component <div id="pieces"&...
  • 3
0 votes
0 answers
25 views

price change by applying a discount

hello I have to make a price modification page but I can't put the value of the price in the input can you help me please I want that in fact I recover the value of the products in the form and that ...
0 votes
0 answers
15 views

Replacing Array Inside a State Object with a Different Length - ReactJS

I have a dropdown of the US States, and when a value is selected, the handleSelectState function is called, which first calls another function to get an array of counties for that US state and then ...
-4 votes
0 answers
33 views

C# find a string in string array [closed]

public string Vertaling(int a) { lines = Resources.vertalingen.Split('\n'); for (int i = 0; i <= 139; i++) { values = lines[i].ToString().Split('\t'); ...
0 votes
0 answers
35 views

what are some ways to simplify this palindromes function? [closed]

link for exercise: https://github.com/zhar1/javascript-exercises/tree/main/09_palindromes I'm fairly new to javascript and going through the odin project. I'm having trouble simplifying my exercises. ...
2 votes
1 answer
34 views

typescript type from string values from an object

The object with values as array of strings: const STUFF = { abc: ["string_1", "string_2"], def: ["string_3", "string_4"], xyz: ["string_1", &...
  • 65.3k
-1 votes
1 answer
34 views

Why are my golang bytes less than 8 bits?

I want to generate a bunch of random bytes (8 1s and 0s), however for some reason crypto/rand makes my bytes different lengths. I tried to make my program like this package main import ( "...
  • 11
-1 votes
0 answers
10 views

Traversing json file with varying keys [duplicate]

I need to access [VARIES][VARIES][runners] the original json file has passed validation. Would a foreach inside a foreach be the way to approach this? Or something similar to the code below. foreach (...
0 votes
1 answer
39 views

Can't make array of arrays [closed]

I'm trying to make an array of coordinate arrays, but I'm blanking out on how to doing. How do I make this happen? Code - targetLocations() { const data = [] const timer = setInterval(() => { ...
0 votes
2 answers
22 views

I wanted to create the array below, but for some reason it gives an error.The array itself was created using numpy

I have an array (numpy) but an error is generated when I run the program itself import numpy as np from sklearn import preprocessing Input_data = np.array([2.1, -1.9, 5.5],[-1.5, 2.4, 3.5],[0.5, -7.9, ...
0 votes
1 answer
34 views

Checking for the presence of an element in the array does not work

Sorry to bother you, but I've been figuring it out for two hours. The problem is that my code adds only one element, but does not add other ids, writes "already have" $(function(){ $(&...
0 votes
1 answer
36 views

C - Weird problems when reading a .csv file into a 2d array of strings

I have a large .csv data file I am trying to read into a multidimensional array (each value in the .csv file is a string) but I am having some unknown problems with the tokenization. My while loop ...
0 votes
1 answer
32 views

Integer array column having more than one value

This column is an integer array type: log_session ----------------------- {105683,105694} {111833} {120285} {108592} {84659,84663} I want to know how many log_session have just 1 value (3 in ...
  • 3,266
-4 votes
1 answer
34 views

Remove the string length from an array and serialised array in PHP [closed]

Is there a way to remove the string length from an array and serialised array in PHP ? for example a simple var_dump on an array displays array(3) { ["fruit"]=> string(5) "apple"...
  • 3
1 vote
1 answer
15 views

How to take multiple char inputs in a single line in C?

I want to take multiple inputs in a single line. #include<stdio.h> int main() { //I am declaring an array char arry[10]; //now i am taking a dynamic input for(int i=0;...
0 votes
0 answers
28 views

state variable inside function having same old value even after update

I'm working on a chat application and when a user scrolls to top, it should load older messages. I managed to do that, but the problem is that, for the second time when I scroll to top, the c.messages[...
  • 57
-1 votes
3 answers
50 views

how can I map given javascript array to an object? [closed]

Can someone please help me resolve below object in javascript? I would be so grateful for your help. //Current Object: Data: { Name: [‘A’, ‘B’, ‘C’, ‘D’], Id: [1, 2, 3, 4] } //Expected ...
0 votes
2 answers
41 views

Dynamically allocate 2d char array of size 10 and get its correct size (i.e 10) using sizeof operator

my requirement is to allocate a 2d char array in c language lets say of size 10 such that if I want to get its size later, I should get 10 as answer. But I am stuck with 2 approaches both having some ...
-1 votes
0 answers
5 views

Write a memo (which includes the whole program code in delphi)

The English HOD asked you to write a small program to assist the English teachers to RAMDOMLY assign learners to do their oral examinations. Each teacher has a different number of learners in their ...
-1 votes
1 answer
34 views

how to count distinct elements of an array which contains different values that are strings

#include<bits/stdc++.h> using namespace std; void solve() { int n,cnt; cin >> n; string s,root=""; vector<string>x; for(int i=0; i<n; i++) { ...
0 votes
1 answer
58 views

recursive function in javascript guide

Hi I'm new to programming and learning from #freecodecamp question arise in Javascript basic course--- what happen in function sum(arr, n) { if (n <= 0) { return 0 } else { return sum(...
-2 votes
0 answers
21 views

Array & Slice type inference [closed]

One thing I really like about Go is that it infers types of variables by using :=. But why doesn't it infer types of arrays like it does on normal vars? If I type number := 1 The type of number is ...
  • 1
-1 votes
1 answer
21 views

merging 2 array of objects of different length based on same property [duplicate]

I want to merge 2 array of objects based on "foodtypeid"of arr1 == "id of arr2 and output a final array with all keyvalue pairs from arr1 and foodCategoryDescription,description,...
0 votes
0 answers
11 views

the getDefaultDisplay() method is deprecated and I don't know how to update it to make my code work more efficiently

the getDefaultDisplay() method is deprecated and I don't know how to update it to make my code work more efficiently. try this: Display display = ((WindowManager) getSystemService(Context....
-2 votes
0 answers
32 views

Java nested loops finding the average of 5 students [closed]

How do I write a Java program that will compute the average scores of 5 students for 3 subjects(3 marks each student) using nested loops? It's supposed to let the user enter 3 marks for 5 times (...
0 votes
1 answer
46 views

If product id is in cart and also in array return matched id (s) [duplicate]

I've got these functions which check product ids in cart but i need to check it against an array of product ids added to a form using the variable $products_ids. This checks for product ids in cart : ...
0 votes
0 answers
48 views

Is there a function in Python that keeps on adding values to an array until a condition is met? (i.e there is no gap less that 2.0 between values?)

I am after a function that produces an array with random numbers(between certain range), where no numerical value can be within a certain constant of another numerical value. This works best if it ...
1 vote
1 answer
57 views

Sorting an array of integers, strings and intergers with alpanumerics in JavaScript

I am trying to sort an array of strings. However some are numbers, some numbers with letters appended, some are letters with numbers appended, and some are purely text. For example: array = ["100&...
-4 votes
0 answers
31 views

I don't understand the first thing I must specify to make a python list comprehension [duplicate]

I understood what theoretically a list comprehension is but with the following syntax can't figure out what the first 'x' means : filteredList = [x for x in list if x > 0]
0 votes
1 answer
28 views

jq select based on two conditions within one child object

I have a json file with the following format {"id": "3DFD4GF", "demographic": [{"country": "Spain", "rating": 7},{"country": "...
  • 173
1 vote
1 answer
19 views

Get columns of 2D ndarray defined by index' in another 2D ndarray

I have an ndarray arr = np.array([[1,2,3],[4,5,6],[7,8,9]]) and an index-array arr_idx = np.array([[0,2],[1,2],[2,1]]) where each row in arr_idx corresponds to the index of arr which I want to have i....
  • 4,429
-3 votes
0 answers
26 views

Cant add object to JSON file qt c++ [closed]

I want to add a new object to "persons" array. I am coding this program in qt framework using c++ language. json file looks like this { "persons": [ { "Name": &...
0 votes
0 answers
16 views

Filter parent & child rows according to one child property

I am facing a bit of troubles on my code rigth now. Let's say I have this kind of Object Node : orderedArticle = [ { id: 1 shippedArticles: [{ id: 1 label: xxx }, { id: 2 label: yyy }] }, { id: 2 ...
-3 votes
0 answers
27 views

JS sort array by substring at end containing numbers and slashes [closed]

I've got some problem here I can't wrap my head around: I've got a vue component that has an array with objects as data which look like that [ { id: 1, images: [<image>, <image>...] ...
-1 votes
1 answer
29 views

Subtracting 2 String Lists and Result should be stored in a New List [duplicate]

I have two String Lists , i want to subtract them and strore result in a new list List_A =['A', 'B' , 'C' , 'D'] List_B =['A', 'D'] Result ['B' , 'C'] Subtracting two string lists
  • 1
0 votes
2 answers
40 views

Unable to append and remove selected tableview cell JSON id in Array in swift

if i tap on cell i need selected cell eventListData?.result?.events?[indexPath.row].id not(indexPath.row) in arrSelectedRowsBuy and if i tap it again then the selected id should remove from ...
0 votes
2 answers
32 views

Generate an m*n matrix with 1 and 0 (No identity)

I need to generate an m*n matrix with 1 and 0 where the sum of each row is 1 and each column is greater than or equal to 1. I'm trying this code but I don't know how to limit my condition on the ...
0 votes
2 answers
28 views

I need to insert a numpy array of a different shape than my other arrays

I am currently trying to insert an array of shape (640, 1) inside an array of shape (480, 640, 3) to obtain a 481x640 array where the first column is juste a line of 640 objects and the other columns ...
0 votes
1 answer
49 views

How to add JS object with nested properties to URL?

I have object similar to this structure: filters = { filters: { categoryFilters: { mainCategory: value1, subCategory: value2 } } } And I am dynamically ...
-1 votes
1 answer
30 views

PHP is array or single object?

I have simple php code: <?php $json = ' { "TrackResponse": { "Shipment": { "Package": { "TrackingNumber": "1Z7V015Y6870100000",...
  • 6,715
0 votes
1 answer
27 views

Exception when trying to print all values in a 2D array using a for loop. Need help understanding the Nested for loop too

I am currently learning beginning to learn Java, using BroCode for Uni, learning how to use For loops to print all values in the 2D array. The code is coming up with an exception in thread: Index 3 is ...
  • 3
1 vote
3 answers
48 views

How to create a new array from this existing array by matching the similar id from an dynamic array

I need to create a new array by filtering the data. { "roles": [ { "role": "manager", "test_id": "123" }, { "role&...
0 votes
2 answers
32 views

Restructure a javascript Array of Objects for Ecommerce categories and subcategories

Input let categories =[ {id:1, name:'Electronics', parentId:''}, {id:2, name:'Devices', parentId:1}, {id:3, name:'Mobile Phones', parentId:2}, {id:4, name:'TV', parentId:2}, {id:5, name:'Accessories', ...

1
2 3 4 5
8237