Questions tagged [array]

An array is an ordered data structure consisting of a collection of elements (values or variables), each identified by one (single dimensional array, or vector) or multiple indexes.

Filter by
Sorted by
Tagged with
0 votes
0 answers
26 views

Generate an array in Ruby efficiently [closed]

I often have a piece of code that creates an array of elements based on some code block and it goes like this ...
Roman Scherbakov's user avatar
2 votes
1 answer
53 views

Recursive Factorial Calculation in JavaScript

...
TAHER El Mehdi's user avatar
2 votes
1 answer
51 views

Dyalog APL dyadic operator deriving ambivalent function to pair two function results

I'm writing a small utility operator which applies two functions to an argument pair and strands the results. The pair can either be given as two arguments or as a single argument with two elements. ...
Adám's user avatar
  • 644
-1 votes
0 answers
48 views

Code footprint of a std::array based container [closed]

I have a custom std::array based container (using class template argument deduction) and want to ask why this working implementation creates more footprint in ...
Andreas's user avatar
  • 99
0 votes
1 answer
47 views

The Matrix Winds In

The Problem: Given an N by M Matrix, Create an Anti-Clockwise Traversal Path that winds in all the way into the Matrix Example: The Matrix is 9 by 5 Output: ...
Amal Krishnan's user avatar
3 votes
0 answers
26 views

extracting values from an array of nested objects without duplicates

I have my solution for the below usecase but I would like to know whether is any other effective solution for the same. My Data: ...
SM1312's user avatar
  • 131
4 votes
3 answers
380 views

Determine whether two arrays have the same elements with the same multiplicities

I have written a Python function called comp that checks whether two given arrays have the same elements, with the same multiplicities. The multiplicity of a member ...
TAHER El Mehdi's user avatar
0 votes
1 answer
40 views

Optimizing the Dig Pow function

I have written a Python function to solve the Dig Pow problem, where the goal is to find a number k such that the sum of each digit of n raised to a specific and ...
TAHER El Mehdi's user avatar
2 votes
2 answers
57 views

Given a sorted list of integers, find the highest count of elements between an indeterminate but fixed size range

I'm trying to optimize a function that takes a sorted list of integers and tells me what is the maximum number of elements in the list between any definite size range. To be clear, the range itself ...
Tyler Schuster's user avatar
5 votes
3 answers
608 views

Merge Sorted Array in Rust

I was solving this task https://leetcode.com/explore/learn/card/fun-with-arrays/525/inserting-items-into-an-array/3253/ The main idea is to merge two sorted arrays (more details in the site) Example: <...
mascai's user avatar
  • 289
1 vote
1 answer
100 views

swap two different length group of variable in array

The code below swaps two different-length groups of variables of the same array in the same array. Is there any other method to achieve this that is less heavy or less redundant? ...
Ill Magnus's user avatar
5 votes
2 answers
105 views

concatenate values and delete the remaining rows using arrays

the below code used to: Concatenate the values on a specific column "N" depend on the value of column "A" then delete the remaining rows. It works, but with range of 30k rows the ...
Leedo's user avatar
  • 265
0 votes
1 answer
24 views

Mangle words to bytearray of lo/hibytes

I would like to refactor the following code snippet adapted from a project I'm involved. It is part of a code to control power outlets via network. The code snippet was written by myself based on the ...
Looser User's user avatar
5 votes
3 answers
2k views

Custom array class in C++

I wrote a custom array class in C++ to suit my personal use case. The main important rule in this project is that no unassigned element is allowed between 2 assigned elements; please review for ...
machine_1's user avatar
  • 521
1 vote
2 answers
44 views

Extend native `Array` instances

I need/want to extend created array instance, to add extra methods that i see as useful. class.labels.js ...
Marc's user avatar
  • 133
5 votes
2 answers
213 views

PHP Fisher-Yates shuffle with random_int

The PHP manual states that the regular shuffle() function isn't cryptographically secure, but that random_int() is. I thought, ...
James G.'s user avatar
5 votes
1 answer
208 views

Dynamic array type using void pointers C

I made my own dynamic array type using void pointers. I'd like to know what you think of my implementation. void pointers are nice but I fear they may be inefficient. The compiler cannot tell what ...
Lead Vaxeral's user avatar
8 votes
4 answers
179 views

Array List C implementation

I want to show you my implementation of the array list in C. Is there something I can improve or fix? Header ...
lester's user avatar
  • 171
6 votes
2 answers
104 views

First attempt at making a sobel edge detection filter in c

I made a borders filter in C. It works properly, but I think it could be optimized and better designed; the formatting is abysmal. It uses too many lines for the border cases and has too many ...
GBA's user avatar
  • 63
0 votes
0 answers
62 views

Bruteforce proof of an arithmetic expansion scheme expression in array lists (Java)

Given a list of, say, integers, one way to implement such a list is to rely on an array under the hood. When we are adding elements to the array list, we might need to make the internal array larger. ...
coderodde's user avatar
  • 26.6k
2 votes
2 answers
162 views

Quick Sort Program

Quick sort is a sorting algorithm in which we select any random element as pivot from the array and we do the partition of the array around that pivot. Basically we place all the elements smaller than ...
Strange Alchemist's user avatar
5 votes
4 answers
217 views

RGB Image Utility Class

I am writing a utility class to store RGB images and do a few utility functions as a way to learn C++. ...
jigglypuff256's user avatar
3 votes
1 answer
89 views

Iteratively paste values from spreadsheet tabs into empty spreadsheet

Basically below code is taking first 7 tabs from my current sheet and pasting them as values in a blank excel sheet with same tab names and saving them in a specific folder by filename I specified. ...
Sorab's user avatar
  • 31
1 vote
1 answer
42 views

Transform an array into object and set index for an unique key in javascript

I have a method that merges keys and indexes from an array into an object. I'm stuck with ways to compress this method, and I don't know what I can do to make it simpler. Goal get an array of objects ...
wittgenstein's user avatar
0 votes
1 answer
83 views

Printing Permutations

Following is a leetcode problem: Given an array nums of distinct integers, return all the possible permutations. You can return all the possible permutations. You can return the answer in any order. ...
Strange Alchemist's user avatar
2 votes
1 answer
46 views

Helper functions to get, set and remove from Firefox browser storage. Also, to get, push and remove from lists stored in the database

I am making a plugin for Firefox, this is (more or less) my first time working with JavaScript. Is this a reasonable design for working with both values and lists in a database? ...
Emil Holmsten's user avatar
2 votes
1 answer
89 views

C generic typesafe dynamic array (vector) try 2

The previous generic dynamic array I asked a review for here was written using only the preprocessor and so while the array itself was type-safe, all the manipulating macros where not. In this try I ...
Itai Nelken's user avatar
2 votes
1 answer
67 views

An implementation of Givens method for diagonalising symmetric matrices

So I tried to create a code which aims to diagonalise symmetric matrices via Givens algorithm. The program only works for symmetric matrices, for we know a symmetric matrix is always diagonalisable, ...
Henry's user avatar
  • 121
2 votes
2 answers
77 views

Follow-up about computing lp norm with MPI

As pointed out in the answer by Victor Eijkhout to this question, the fact I am broadcasting the same vector to each process is against the MPI principles and, most importantly, will be a bottleneck ...
bobinthebox's user avatar
2 votes
1 answer
330 views

Compute lp-norm of a vector in parallel with MPI

I'm trying to solve the following exercise: Compute in parallel with MPI the lp norm of a vector of a predefined size N ...
bobinthebox's user avatar
2 votes
1 answer
113 views

Swift - efficient array searching

I am trying to find a way to search an Int array (all numbers are > 0) and identify sequences where the sum of each element is a specific number. One element can ...
koen's user avatar
  • 169
10 votes
5 answers
2k views

Implementation of a two-dimensional array in C

I implemented a two-dimensional array in C and would like to know if the implementation is sound in terms of Memory management Potential bugs and other side effects that I missed Code style (...
Gilfoyle's user avatar
  • 1,115
3 votes
1 answer
102 views

How can I condense my code in node.js for sorting unique values within an array?

Kattis problem - ("I've been everywhere") I would highly recommend looking at the problem through the link, however I will summarize it a bit here and explain the functionality of each part ...
doroshm's user avatar
  • 33
4 votes
2 answers
205 views

Robust input for lottery tickets

I've made a method that provides a robust way for a user to fill out a lottery ticket. During this process I found out that Java also provides syntax for labels. That was very astounding for me. But I ...
Dexter Thorn's user avatar
  • 2,102
1 vote
1 answer
113 views

C# Get All Diagonals Jagged Array

How can I improve this? The idea is to store every left to right diagonals in a list Not looking for a more efficient algorithm instead something readable, LINQ perhaps? input: 3, 1 2, 5, 7 1, 5, 8, 3,...
Laycoonz's user avatar
  • 103
2 votes
1 answer
82 views

Multidimensional array in Java

I have this multidimensional array that generalizes vectors and matrices: com.github.coderodde.util.MultidimensionalArray.java: ...
coderodde's user avatar
  • 26.6k
4 votes
3 answers
336 views

Removing repeating rows and columns from 2d array

This is a real problem I had to fix recently. Imagine having generic array where you can have duplicate columns and rows. You want to remove those duplicates as long as they are next to each other. <...
K.H.'s user avatar
  • 2,538
1 vote
1 answer
90 views

Array Implementation In JavaScript

Review I have written my own implementation of Array in JavaScript with the basic functionalities. Can anyone please review this code and point out the mistakes/how to make the implementation better? ...
enigma6174's user avatar
2 votes
2 answers
69 views

delete multidimentional array value in php

I made a program that converts JSON to a PHP array and checks every value of the multidimensional array with a loop and if a value matches certain values then it deletes that key and value and ...
mahmoudkhani's user avatar
6 votes
2 answers
105 views

N dimensional array index utility

I created the below class to help working with ND Arrays, mapping based on this question. This will help in implementing the code for handling convolutions. How can I improve upon this? Is there ...
Dávid Tóth's user avatar
3 votes
2 answers
350 views

Calculate sum of largest sequence of decreasing odd ints

I wrote a method that finds the maximum sum of consecutive decreasing sequence of odd integers. For example: if sequence is 13 9 7 12 13 15 13, then sum is 29 (13 + 9 + 7). I don't think it's as good ...
infelixPuer's user avatar
-2 votes
1 answer
609 views

How to split a file with multiple lines into fractional array elements?

I have a file with content: 4;10;3;6;10 6;9;1;3;5 3;2;1;1;2,65 I need to split each line of the file into an fractional (double) array with elements as these ...
krakozyabrr's user avatar
3 votes
1 answer
172 views

JavaScript BitArray Implementation

I am working on a project in which an array can easily grow beyond 50M in length. It's an array holding only boolean (0/1) ...
Redu's user avatar
  • 856
1 vote
1 answer
81 views

Selection algorithms (order statistic) in Java: linear time vs. sorting selector vs. Quickselect

This post is about computing order statistics: given an array \$A\$ (not necessarily sorted), find the \$k\$th smallest array component. The entire repository is here. ...
coderodde's user avatar
  • 26.6k
2 votes
1 answer
165 views

Generating random number of randomly sized Squares/Rectangles using numpy arrays

I made classes to use in generating square/rectangular shapes on a texture. ...
Nyos's user avatar
  • 21
3 votes
1 answer
138 views

SetTimeout to populate Javascript Object while a function looped AJAX requests to get data

I wrote some code that will get the name and data of a node or multiple of nodes and put them in an object (seriesData) so I can use said object for a chart (renderChart). I used setTimeout() so ...
Bewarden's user avatar
4 votes
2 answers
480 views

Unit testing for a multi-dimensional array class

I have designed a class bunji::Tensor which is a multi-dimensional array. I have designed it to have a similar interface to a multi-dimensional ...
finlay morrison's user avatar
1 vote
1 answer
47 views

Implementation of a multi-dimensional array as a single memory buffer [Part 2]

A couple days ago I posted my first implementation of my data structure here, which implements a cache-optimized tensor representation. I have worked the ideas from the responses into my ...
finlay morrison's user avatar
3 votes
3 answers
155 views

Implementation of a multi-dimensional array as a single memory buffer

There is an updated version of this code with some of the recommended changes made here. I have created an implementation of a multi-dimensional array which utilizes a single continuous memory buffer ...
finlay morrison's user avatar
5 votes
3 answers
181 views

Sum of natural numbers below threshold

I have this code: ...
Shum's user avatar
  • 53

1
2 3 4 5
43