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

2
votes
0answers
9 views

Validate input of month/year, otherwise set it to current month/year

Is there a cleaner way of doing this? I'm using filter_input to first check for valid input, then using it again to assign the variable. Also, my condition in ...
3
votes
1answer
32 views

Polyglot function to sum all the numbers in an array in Javascript and PHP

This, again, is a very simple code. This is my 2nd polyglot question and this time I've tried to do something that I miss sometimes in Javascript. PHP has the ...
3
votes
2answers
70 views

Generic dynamic array

Here is the interface of my generic dynamic array; ...
-2
votes
0answers
6 views

How to check the vlaues of two array and based on that checkbox needs to checked [on hold]

I'm having two arrays, which contains the values. Out of which one array is always greater than other. I need to check the values of two arrays, if they are same the check-box needs to be checked. I'm ...
0
votes
0answers
28 views

Pulling specific random values from a PHP array [on hold]

On the page I'm creating there is graphic representation of pigeon-holes with five compartments for new comments. If there is new unread comment it should show up as graphic in one random compartment. ...
3
votes
1answer
71 views

Sorting thousands of records

I have the following list to sort: A 0.53 B 0.56 C 0.56 D 0.98 E 0.33 Please note that my list may contains thousands of such type of records. I am sorting my ...
4
votes
2answers
65 views

Text files: Copy, Rename, Append/Merge together

I wrote 3 subroutines related to batch data processing, they will be used together. A bit of background, I wrote this for my admin colleagues who do not write code. An application dumps daily ...
3
votes
1answer
53 views

Rectangularize a list-of-lists structure

Considering I have an iterated "lists of lists ..." (up to 4 dimensions), now I wish to make the full list "rectangular" (or well each dimension equal in size). For a 4 dimensional case I've written ...
4
votes
3answers
919 views

Array Sorting in C++

I have this simple implementation for array sorting: ...
1
vote
0answers
47 views

Dynamic Programming with large arrays

Last week we have finished our program which applies a local search. At this moment the program needs more than three hours for the largest instances. The three hours are too long and we try to ...
0
votes
0answers
15 views

Remove elements from an array [closed]

I'm trying to do a code which works with arrays, the thing is that I need to do a method delete(Object e) which has to delete all the objects in the array that equals "e", the thing is that I can't ...
2
votes
1answer
66 views

Array implementation of unbalanced binary search tree

I'm preparing for an interview. I tried implementing binary search tree in C++. I used array but it seems to be complicated to restructure the array while deleting nodes. Is linked list a better data ...
0
votes
1answer
42 views

Generate all permutations

I have written this Java snippet to generate all permutations of a given array of integers. Can somebody review it and give some pointers as to how to make it more generic? I.e. instead of dealing ...
5
votes
2answers
164 views

Matching words with a scrambled word

I have this code that reads in a "scrambles" and a "words" file. It compares both files using their canonical form and prints out the words from the "words" file that match a particular scrambled ...
2
votes
1answer
85 views

Join two arrays into a single one

I put together a function to sort out values that I am getting from a curl request for different 'devices', it works as is, I am only wondering if there is an easier way to to this. ...
2
votes
2answers
45 views

Find index of an object with a specific value stored in an array

I am using the following code in order to retrieve the index for an object stored in a JavaScript array. Scripts works fine, but I would like your opinion regarding performance. Also would like to ...
0
votes
0answers
33 views

Rendering JSON array as a tree

This code is working fine for me, but I want to simplify it. Function parents is defining parents of the tree and children ...
4
votes
3answers
53 views

Reserving seats in a movie theater

I'm writing a C program to reserve seats in a movie theater. I am validating the selection of seats: ...
1
vote
1answer
64 views

Populating an HTML combo box by looped concatenation

This code takes the results of a database query and uses them to populate the options in a combobox on a form. Would it be better to start with an empty htmlCode ...
1
vote
2answers
73 views

Show first n elements of array, and count elements not shown

This code mimics the "likes" tooltip from Facebook. Given an array with the list of users that liked the content, it shows the first n users and displays a final item with the count of the users not ...
2
votes
2answers
262 views

Filter out duplicates from an array and return only unique value

I have the following script, which filters duplicates and returns only unique values for an array. When passing false or nothing the "original" array is ...
0
votes
1answer
45 views

Remove particular element from an array and return indices of other elements

I'd like to get the indices of elements of an array with particular element. Is it okay or, or how can I make it even better? ...
4
votes
0answers
49 views

Mapping arbitrary Int values to a linear index space

This is part of a growing "primitive" tools collection here on github, and is the initial use-case for the IntArray for review here. Often, when processing data, you encounter unique values that you ...
6
votes
2answers
205 views

Finding pairs of numbers within A that add up to N

I am working on an interview question from Amazon Software Interview: Given an integer N and an array of unsorted integers A find all pairs of numbers within A which add up to N I have a working ...
10
votes
2answers
91 views

Using 2D arrays to make more efficient sequential storage

This code is part of a growing "primitive" tools collection here on github Use Case Consider: ...
1
vote
4answers
53 views

Finding the second largest element of large input sets

I have a problem where I need to find the second maximum element of the user inputs. It's an online practice problem and I can't figure out why the server responds back with a Non-Zero Exit Code error ...
2
votes
1answer
40 views

Reading and Converting XML File to Array

I'm using WordPress ( PHP Based Platform ) and I'm trying to read an external XML File, convert it into a usable array, then compare two arrays - one from the xml file and another from an options ...
3
votes
2answers
45 views

Transform a string into an array based on grouping rules

I've got a simple spec for defining character sets, ranges, or wildcards. I'd like to take the string and appropriately create an array based on these rules. I have a solution but I'm sure there is a ...
3
votes
1answer
46 views

Dynamic array implementation

I would like to use code below for general purpose dynamic array implementation in my future code. How does it look? array.h: ...
10
votes
4answers
156 views

Lottery number generator

...
2
votes
4answers
94 views

Returns an array of all inputs with specified name

I've made a nice little function to return a NodeList array containing all the inputs that have a specified name attribute: ...
0
votes
3answers
98 views

Finding all integers in an array with odd occurrence

I am doing an interview exercise problem from here. The problem is to find "all numbers that occurred an odd-number of times in an array". Here is my high level psuedo code thinking: Construct a ...
4
votes
2answers
105 views

Binary search that returns bitwise complement of missing index

While re-writing some old JavaScript code to better handle large arrays, I ended up writing my own binary search method. I found many examples of binary search methods written in JavaScript, but all ...
0
votes
1answer
53 views

Passing an array in a hyperlink

Maybe this is fine the way it is, but it seems messy. Basically I have dynamically generated HTML that will display a list of songs in a given folder. Each song has an ID, and I want to add a button ...
7
votes
4answers
457 views

Reversing the lines of a file

I am trying to reverse the lines of a file by reading the file through an array. Is there a more efficient and quicker way of achieving this? ...
6
votes
2answers
131 views

Choosing a random flat color

I have a big array of custom flat colors with perhaps 100 lines: ...
0
votes
1answer
26 views

Bridge Transport - contest practice

I'm practicing for a contest by doing some of the older problems, and I was wondering if there are more efficient ways of doing this or if I'm not following any coding conventions. Most importantly, I ...
8
votes
3answers
340 views

Two sets came to an intersection

Challenge: Print set intersections. Specifications: Your program should accept as its first argument a path to a filename. Each line in the file is a test case. Each test case contain ...
8
votes
4answers
380 views

Calculating range of ArrayLists

I have written this method which calculates the range (max - min) of an ArrayList. I have two for loops each for a different ...
3
votes
1answer
82 views

Stack with Array

Just coded up a simple Stack using an Array in Java for practice. Other than the lack of JavaDoc (still need to learn that part), did I cover all the bases? ...
4
votes
3answers
116 views

Aggregate array values into ranges

In five minutes I made a pretty ugly looking function. Can you help before I have to commit the code into history? Requirements: I would like a function that takes an array of numbers, and ...
3
votes
4answers
104 views

Concatenate two arrays generated randomly

I have written the code to concatenate two arrays . Please let me know of any loopholes in the written code. ...
15
votes
4answers
1k views

Duplicate like a weapon, arrays like heaven

Challenge: Find the duplicated entry. Specifications: Your program should accept as its first argument a path to a filename. Each line in this file is one test case. Each line ...
3
votes
4answers
174 views

Count the ways to partition an array into two equal sets

I need to count the number of ways to partition an array into two contiguous arrays such that those arrays contain exactly same set of items. Suppose ...
1
vote
1answer
45 views

Merging website info into an array

I'm scraping a title and a link from a website and placing them in a single array. The $i variable seems a bit wrong to me, or is it perfectly fine? ...
1
vote
1answer
60 views

Party Invitation - Trimming the Invitation List

I am learning Java right now and am coding some simple programs to practice. Right now, one of my for loops has an inelegant way of ending the loop. I was wondering ...
5
votes
1answer
228 views

Listing the first 100 prime numbers

I thought of this implementation, and I want to get feedback from you.. what design would you use for printing first 100 prime numbers? I used the fact that, if the number is not divisible by any ...
3
votes
2answers
89 views

Removing duplicates from an array

I recently wrote this JavaScript algorithm for removing duplicates from an array as part of a job interview process, but was turned down for the position after submitting the code. I didn't receive ...
3
votes
2answers
68 views

Sort ArrayList in a better way

I have a list of categories (in this example I used String but in my project I have a model) which must be sorted like this: on top we should have 2 categories ...
4
votes
1answer
439 views

Polyglot array_extend() function for Javascript and PHP

This is a polyglot function I've made out of fun. The goal is to grab n arrays (or Javascript Objects) and 'extend' them in ...