Tagged Questions

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.

learn more… | top users | synonyms

0
votes
2answers
41 views

Simple print function, passing in various arrays [on hold]

I wanted to create a print method that could take in a given array and print it. I can only seem to make the print function specific to my specific array. My print function only can print 1 array, but ...
0
votes
1answer
45 views

More elegant array multiplication than multiple concat statements

Background Trevor wishes to duplicate an array, transforming it by multiplying its elements four times. Existing Solution ...
1
vote
1answer
38 views

Create an Array with n values that is able to use Array methods instantly

As it is impossible to use Array methods on new Array(n), e.g. new Array(5).map(/* [some callback] */), I deviced a pseudo ...
3
votes
1answer
35 views

Comparing two implementations of smoosh()

In this question, the suggested solution for smoosh() is as shown below, ...
6
votes
1answer
57 views

Returning multiplied matrix array

Is there a more clever way of writing this piece of code? It does work but I thought there might be a better way of returning a matrix from multiplying the parameter by itself. ...
3
votes
1answer
27 views

Generating a complicated data structure in a more efficient manner

I need to convert some CSV data into a format recognizable by some old script my work uses. Changing the format is pretty much out of the question. So I've written this: ...
3
votes
1answer
47 views

Traversing a tile-based 2D-array map using keyboard controls

I've produced the beginnings of an RPG-style game using HTML5 and canvas. So far you can use the keyboard controls WASD to move an avatar around a simple tile-based map. The map is constructed of ...
6
votes
4answers
229 views

Optimizing smoosh() method further

Part I of this question says: Fill in the smoosh() method in the Homework3 class so that it performs as indicated in the ...
2
votes
0answers
39 views

Sorting an array to match the order of values of another array

I'm running hundreds of curl operations in parallel to my own API, the response array that I get is out of order ( the reason being that the first one to finish gets added to the response array ...
-3
votes
0answers
37 views

How do I finish this up? Sorting a list of arbitrarily generated integers [closed]

Write a program that will sort a list of arbitrarily generated integers in descending order. Let the user determine how many arbitrary and unique numbers to sort from 1 to 10000. Use the random ...
4
votes
1answer
63 views

Using array values to create variables, if statements and highchart dataset

I am trying to make my script maintenance-free by replacing some "static" variables and labels with dynamic ones. The main function of my code is to extract data from a SharePoint-list which contains ...
13
votes
4answers
397 views

Array alive/dead entity “refresh” algorithm

I have an Entity class that can be either dead or alive. I store entities contiguously in a resizable array. During an ...
2
votes
2answers
142 views

Function that takes an array of integers and returns that array rotated by N positions

Example: if \$N=2\$, given the input array \${[1, 2, 3, 4, 5, 6]}\$ the function should return \${[5, 6, 1, 2, 3, 4]}\$ Here is my code: ...
3
votes
2answers
74 views

Making this arraycopy more efficient

I'd like to find out how I can make my function more efficient: ...
3
votes
1answer
23 views

Loop through products and return first product that matches criteria

I am writing a function which loops through an array of products. The function needs to return: the ID of the first product that has an image and is ...
6
votes
4answers
214 views

Simple resizable array

In some (lower-level) parts of my codebase I often have the need to allocate resizable array storage for certain objects, that usually are not default-constructible. I created a simple class using ...
5
votes
1answer
32 views

Concurrently Iterable Poor Array List

As I wrote on SO, I need an ArrayList-like structure allowing just the following operations get(int index) add(E element) ...
6
votes
1answer
47 views

Passing a 1D array (single column of a Range object) to .NET to manipulate it without loops and returning it back to VBA

Background Kind of a follow up - slightly related to my other SO question. I thought that if somehow I find a way in VBA to pass a single column to .NET and convert it to a native .NET type then I ...
3
votes
2answers
258 views

Squaring numbers in an array

I want to know if there is a better way to square numbers in an array. This is what I wrote: ...
6
votes
3answers
265 views

Copying one array to the end of another array

I wrote a program that places values in one array to the end of another array. It keeps the order of the values. If the second array is bigger, then there will be leading zeroes. Is there anything I ...
2
votes
3answers
70 views
2
votes
1answer
57 views

Calculate percentage of values in an array with a certain condition

I had to write a function that calculates the percentage of values in table less or equal to 2. Is my code right or is there anything missing? ...
6
votes
3answers
135 views

Byte swapping functions

I recently programmed some byte swapping functions. As a special I did a function which can convert an entire int array. I please you to look at the following aspects: portability performance ...
4
votes
3answers
128 views

Implementing an ArrayList

I implemented ArrayList functionality in C as follows: ...
2
votes
2answers
60 views

Extracting maximum values from each of the subsets of an array

Problem description: I have a numpy array cps from which I want to extract the maximum value in each of the subsets of the array (a subset is defined as non-zero ...
-1
votes
1answer
55 views

ArrayList implementation in C [closed]

Although I know I can use calloc then realloc to make a dynamic array in C, and that I also need a variable to keep track of the ...
5
votes
1answer
68 views

Efficiently displaying elements in an array

I wrote the below method to list out the elements of an array, as well as adding the Oxford comma to the list if desired. However, my for-loop looks, perhaps, a little convoluted. Is there a better ...
4
votes
4answers
341 views

Array Implementation of Queue

I've implemented the queue data structures using array in java. Anything I need to change in my code? Queue.java ...
4
votes
2answers
180 views

Printing element combinations that make a neutral compound

An array is given with the element name and their respective pH values. Print the combination of 2 elements which make a neutral compound Here is the solution that I came up with but uses a ...
5
votes
1answer
226 views

Shortening jQuery array

In short, the code picks up to 9 different ids from li in jailplayer. If a hillside, it ...
3
votes
0answers
30 views

Simplifying the building of an adjacency array starting from a flat structure

Purpose: to make an adjacency PHP array with parent_id, name, level and ...
14
votes
3answers
951 views

Project Euler #1 in PHP

The code below works & as far as I can tell the result is correct. Would you please review and let me know what I could have done better? I tried to use variables as much as possible, that way it ...
4
votes
1answer
44 views

Bernoulli trials using a condition in a vectorized operation

I was wondering how to vectorize the following code instead of using the for-loop and still be able to check for a condition. ...
7
votes
1answer
62 views

Merging lines of an array

I've got an array like this, which is a result from a Google analytics request. I asked for the amount of visits for the last three months. ...
5
votes
1answer
58 views

Optimizing a loop for catalogue manipulation

I have a catalogue of 56000 objects and I want to replace some columns with new values for instance replace NaN with -99 and ...
5
votes
2answers
44 views

Select grand child in array knockout

I'm trying to select a grand child from an array in an array. If it was C# I would have wrote something like below ...
3
votes
2answers
58 views

Determining the value of a position on an array based on its nearest datapoint known value

I was wondering what would be the efficient way to determine the value of a position on an array based on its nearest datapoint known value in Python? Problem description: There are ...
6
votes
1answer
75 views

Generating DOM from a complex strings via arrays

This is a revised and expanded version of Transforming complex strings into simple arrays My function grabPerson turns strings of user information from multiple ...
7
votes
1answer
55 views

Improved manipulation of a 2D array for a game map

I have a 2D array (or rather, an array of arrays) representing tile maps in game. The 'world' map array holds smaller arrays representing individual map parts which I am calling 'rooms': ...
4
votes
2answers
96 views

Find sum of number of times that each character of source occurs in the target

I wrote the following code in response to this question "find sum of number of times that each character of source occurs in the target", is there any better solution for it? Analysis ...
5
votes
4answers
277 views

Find the number of times that the difference of array values are equal to the number

I wrote the following code to answer this, but I am wondering if there is any better approach. For example If the following array is given: {10,21,34,45,56} ...
7
votes
2answers
119 views

Array-like container for uints shorter than 8 bits (Rev 1)

This is a follow-up to Array-like container for uints shorter than 8 bits In short: The PackedBitfieldArray should be a kind of container for packed (unsigned) ...
11
votes
1answer
135 views

Array-like container for uints shorter than 8 bits

Follow-up: Array-like container for uints shorter than 8 bits (Rev 1) First of all: yes, I need this kind of array to generate data for a piece of hardware, and it must be stored and manipulated ...
2
votes
1answer
37 views

Best practise way to handle array of pairs

I am trying to randomly select 4 items out of an array, each item has an index, a name and a price attached to it. Currently I have the following code segment to select 4 at random: ...
8
votes
1answer
83 views

Compare the index of each char in a string in an alphabet array to a range of numbers

I saw this codegolf challenge and I set out to try and write a solution for it. I'm nowhere near an expert codegolfer (or programmer), but it was an interesting exercise. Now I'm wondering how to ...
7
votes
1answer
472 views

Breaking a chess coordinate string into 2D coordinates

Given a chess coordinate as a string (e.g. "a1") I'd like to transform it into a 2-D array (so, for "a1" I'd like to get [1,1]). Here's what I came up with: ...
4
votes
2answers
105 views

Array kept contiguous by swapping with the last element

I made a class that encapsulates the common pattern of keeping an array contiguous when an element is removed by swapping the last element into its place. A few specific things I'm wondering about: ...
3
votes
2answers
88 views

Cleaner structure for Battleships code

The code provided is working fine, but I would like to see if there is room for improvement for the code provided: ...
6
votes
2answers
199 views

Array from file

I have this code which is performed each time I click the 'show polygons' button. The problem is that it takes a few seconds to finish running through the code before actually drawing the polygons + ...
2
votes
1answer
43 views

Compare 2 dynamic jagged arrays of doubles and arrays of doubles

I want to be able to compare 2 jagged arrays of doubles for value equality. The arrays can have any number of dimensions. Inside any dimension could also be another array etc. It is known that the ...