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.
0
votes
0answers
4 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
133 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
70 views
Making this arraycopy more efficient
I'd like to find out how I can make my function more efficient:
...
3
votes
1answer
22 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
208 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
28 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
41 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
253 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
262 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
59 views
2
votes
1answer
53 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
131 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
121 views
2
votes
2answers
57 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
48 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
332 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
174 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
221 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
28 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
935 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
39 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
56 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
42 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
57 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
54 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
95 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
276 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
116 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
76 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 ...
6
votes
1answer
462 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
96 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
87 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
197 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
40 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 ...
2
votes
0answers
54 views
Extracting data from an array of arrays, PHP style
I was browsing Stack Overflow recently and saw a PHP question about rearranging an array of arrays for printing. The initial data structure looked like this:
...
4
votes
3answers
145 views
Merge Sort Implementation in Java (that seems slow…)
I decided to write my own implementation of merge sort. Here is the code:
...
11
votes
4answers
1k views
Hackerrank “Sherlock Holmes” challenge
Watson gives to Sherlock an array: A1, A2, ⋯, AN. He also gives to
Sherlock two other arrays: B1, B2, ⋯, BM and ...
0
votes
1answer
41 views
Storing array inside closure
Is storing array values inside of a closure considered to be bad practice? I having been trying to decide if I should just use a standard object with key value pair. This is not the method I am ...
5
votes
1answer
126 views
Special summation of integer array elements
I looked at this question and thought that I could find a much simpler way of doing this, here is the criteria that was given:
My current task is to find a score from an array where the ...
6
votes
3answers
127 views
Convert dict entries to sets and lists
Can you please tell me if there is a better way to do this?
...
13
votes
5answers
1k views
Reverse words in a given String
I'd like this code to be improved
Input string: codereview is awesome
Output string: awesome is codereview
My approach:
...
13
votes
4answers
734 views
Random name-picker with array
I created a program that picks a champion for a role on the game League of Legends using arrays and random numbers.
Is there a quicker and more efficient way of doing this?
There is one form that ...
1
vote
1answer
87 views
Finding Duplicates in Java
I am trying to figure out a way to make finding duplicates in Java more efficient. I started off with this:
...
2
votes
1answer
90 views
Generating sorted array in descending order
I have a method that generates a sorted array with random values in a given range. I wanted to make a method that does this but in descending order.
The easiest way to accomplish this is to call the ...
4
votes
2answers
508 views