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

3
votes
2answers
73 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 ...
3
votes
4answers
143 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} ...
6
votes
2answers
43 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) ...
9
votes
1answer
115 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
31 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
53 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
446 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
83 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
70 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
182 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
35 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
44 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
109 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
97 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
114 views

Convert dict entries to sets and lists

Can you please tell me if there is a better way to do this? ...
12
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
654 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
75 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
74 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
349 views
3
votes
2answers
58 views

in_array() in Go

This function's objective is very simple. It takes array and checks if val is a value inside of this array. It returns whether ...
8
votes
5answers
384 views

Randomly generating a sorted array

I'm writing a method that generates a random integer array that are sorted. It takes the arguments of min value, max value and the length of desired array. So for example the arguments with min val = ...
8
votes
2answers
307 views

Remove Empty String array from ArrayList

I am trying to remove empty a String array from ArrayList: ...
2
votes
1answer
56 views

Refactoring while-do into tail recursion with F#

I have a while-do loop nested inside a while-do loop in my program, due to it needing to iterate in two dimensions through an array of arrays, and originally my loop looked like this: ...
4
votes
1answer
58 views

Is this a good algorithm to unflat js objects?

I am dealing with a scenario where I get data in the following form: ...
0
votes
3answers
87 views

Linked list vs array performance for RemoveAt() function [closed]

I am trying to compare the RemoveAt() function performance in an array and linked list. For array: ...
3
votes
2answers
131 views

Shuffling array elements in C

This is an answer to this problem. Basically, given an array, swap the given number of elements in the array. The solution that came to my mind: since we always swap at least two elements, pick two ...
7
votes
2answers
315 views
7
votes
3answers
388 views

Ticket management system

I am building a ticket management system for a state server we use at work. Back end is node.js with multiple front ends. I am rewriting my back end to be more maintainable as the scope grows. For ...
7
votes
5answers
399 views

Checking if an array is sorted

I've come up with two ways to check to see if array is sorted and return true if it is. ...
5
votes
2answers
75 views

Array 2D pairwise function

I found myself in the need of a function to pairwise an array 2D so I created one: ...
3
votes
4answers
136 views

Returns values for a specific array and key

This code is intended to take an array and a key as inputs, and return an array of the values paired with that key. ...
7
votes
3answers
274 views

Index into array as if it is circular

The problem: Treat an array as if it is circular; out-of-bounds indices "wrap around" the array to become in-bounds. Current solution: ...
3
votes
1answer
95 views

Locating a bitmap inside another (larger) bitmap with F#

This is my firstish (heavily rewritten) go at the completed project that I've been working on with CodeReview assistance, so further advice is appreciated! See here, here and here for the past history ...
2
votes
2answers
190 views

Efficient way to iterate over elements of array for matching contents of another array

Using jQuery I'm trying to find an efficient way to iterate through an array excludeMe and check if elements from another array ...
7
votes
4answers
96 views

Use a Java Array like a List

I'm saving string values in an array one at a time so I cannot initialize the array with the values all at once. After I'm done with the array I need to pass it to another class that is expected a ...
5
votes
2answers
97 views

Initiating class objects and arrays

I have a class that always has 14 instances. I'm just wondering if there is a better or more effective way of doing this. In this class I also have an array that is filled by calling 4 functions ...
6
votes
2answers
189 views

How can I quickly find unique list items?

I use the loop-every-single-list-item approach to filter out unique elements in a given list, which tends to be very inefficient way as a list grow in size, or as function call frequency increases. ...
7
votes
1answer
251 views

Program to insert, search for and delete an element from an array

I'd like this code to be improved. ...
3
votes
1answer
56 views

Transforming a byte array into an array of byte arrays with F#

This code is intended to be used with an image manipulation library that I'm working on, and the goal is to take the raw byte[] data from an image, and transform it into a 2D array where each position ...
3
votes
2answers
94 views

Returning nested array with added key=>value

This works, but do I have to make a new array, result, or is there a way to just insert the field I need into each $key of the ...
8
votes
2answers
146 views

Finding the longest Collatz sequence cycle

I wrote a program to calculate Collatz sequences for initial numbers between 1 and a given integer i, then find the one with the largest cycle length. My code is ...
4
votes
1answer
124 views

Converting string array to string (and vice-versa) for storing via XML

I'm using XML to store data and I need to store a string array in it. The best way (that I can think of) to store a string array is by converting it to a single string. In order to do that, I'm using ...
7
votes
2answers
79 views

Program to find the element in an array

I'd like this code to be improved. ...
4
votes
2answers
93 views

Implementing write sphere of values to 3D array

The code below is sort of complicated to explain... It writes a "sphere" of data to a 3D array from the given 3D-Position outwards in a spherical shape based on the given radius and value to write. A ...
7
votes
3answers
282 views

Find two unique integers in sorted array

I have to write the following method: I have sorted array of integers and in this array every integer repeats twice, except two elements. I have to find these two elements. Input: 1, 1, 2, 3, 3, ...
4
votes
5answers
198 views

Search algorithm for specific values in a 3D array/matrix being super slow

I'm trying to create code that reads a text file (containing (double) numbers between 0 and 1) and filling up a 3D array/matrix (calling it matrix from now on) with ...
2
votes
1answer
47 views

Duplication Elimination Project [closed]

I am currently doing a project for school, and I am completely stumped. We are only on Chapter 8 of C# Development 1 and I have a question about the code. The project is: Use a one-dimensional ...