Tagged Questions
11
votes
4answers
313 views
Why is this code so much faster (relatively) in IE7?
Here's some code that I ran through jsperf to assess its performance. The first test (named EvalLengthBefore++ in the images below) is the way I would consider normally looping through the elements of ...
10
votes
3answers
243 views
Displaying random quotes from an array
Is there anything that I could have done better in this code?
...
10
votes
3answers
514 views
Writing a function to add or modify an existing object inside an array
I have an array of objects. Each object has two properties, id and quantity.
I wrote a function to add an object to the array. ...
8
votes
2answers
362 views
Rotating array members
I had a situation when I needed to move all array elements in circular fashion. When I say this, I mean:
0 1 2 3
1 2 3 0
2 3 0 1
3 0 1 2
So the array:
...
5
votes
2answers
112 views
Simple tasks list
I am still learning the javascript language.
Recently I've written simple code for a task list. I am searching for improvements and advice from more experienced users. Are there any improvements, ...
5
votes
1answer
90 views
5
votes
1answer
36 views
Loading car photo's
I have been developing a small application for a client which combines two arrays together and then creates a URL and then loads the images on the same page from the given URL.
I'd like you to look ...
4
votes
2answers
53 views
Multicriteria sort array javascript
I have an array of objects that I must sort based on two criteria. I've come up with a solution but I'd like to know if there is a better way to do it.
Assume a list of devices:
...
4
votes
1answer
96 views
Making an array editable by user
What I want to do:
Let users add data to an array through an input field and add button.
HTML:
...
4
votes
1answer
52 views
Computationally efficient way of comparing and merging like object keys
Though I can achieve most ends via a series of conditionals and arithmetic, especially when iterating over or comparing arrays I frequently hear of much more efficient implementations.
Hailing from ...
4
votes
1answer
574 views
Cross-browser DOMTokenList object and wrapper function. Failures and improvements?
I have been looking for a Cross-browser solution for DOMTokenList and element.classList. I wasn't able to find much for ...
4
votes
1answer
892 views
Rearrange elements in two-dimensional array spiral order
Recently I was asked to write algorithm to rearrange elements in two-dimensional array in spiral order.
Input array: Output array:
...
3
votes
3answers
248 views
Improving the code to turn a string into an array of numbers?
I have a string of numbers, like "31654918562314", and I want to convert it into an array of integers. The code I've written is:
...
3
votes
3answers
155 views
re-write javascript array
I am using a long array of over 300 var & 7,000 lines of code written like this:
...
3
votes
2answers
114 views
Calculate all possible combinations of an array of arrays or strings
I'm using code adapted from this Stack Overflow question to calculate all possible combinations from an array, which may contains strings.
For example:
...
3
votes
1answer
3k views
Better Javascript to find unique values in an array
My objective is to make an array of unique keys from a list of objects. Example:
Input:
var input = [{"a":1, "b":2}, {"a":3, "c":4}, {"a":5}]
Output:
...
3
votes
1answer
343 views
JavaScript shuffle idea
Based on the standard implementation of Array.sort in JavaScript, would the following be a reasonable way of shuffling the contents of an array? Is it moderately ...
3
votes
1answer
236 views
C# Array Mutator Methods to mimic JavaScript Array Mutator Methods
Between .NET's built-in collection libraries and LINQ extension methods, I never have to use arrays. An unfortunate consequence of this is that I am probably less competent in working with this very ...
3
votes
1answer
82 views
2-dimensional “wrapping” array
I'm writing a simple JavaScript game, which uses a 2-dimensional array as the main data structure. I wrote this function-class-thing that allows me to give any two integers, positive or negative. ...
3
votes
0answers
77 views
Creating collisions for a breakout style wall [on hold]
I am creating a breakout style game as an introduction to JavaScript, and would like to know whether the way I have gone about doing this is efficient/viable. As well as needing assistance with ...
2
votes
3answers
239 views
Cycling between element above and below current array element
The title sucks, but it's really very simple - given an array and a starting element, cycle between one element above, below, then two element above, and below the starting element. For example:
...
2
votes
2answers
54 views
JavaScript Array Comparison (aka Set Comparison)
I want to compare the values in two arrays. The order of the values doesn't matter. Basically they are two Sets. This function returns true if the values are the same in both arrays, or false ...
2
votes
1answer
53 views
Create object-properties from an array
I'm writing a simple table-oriented storage for objects. The schema of a table is stored in the columns-array and the data in the ...
2
votes
1answer
164 views
Implement numbering scheme like A,B,C… AA,AB,… AAA…, similar to converting a number to radix26
I want to implement numbering scheme like Microsoft Word uses for numbering.
first one gets = A,next is B, next is C, .... then AA, then AB,....and so on.
as shown below
...
2
votes
3answers
255 views
Japanese rehearsal system
At the moment I am trying to create a Japanese rehearsal system, and it's working perfectly. However, I am not pleased with the code. Basically I had a .txt file called lesson1.txt. I saved it as ...
2
votes
1answer
95 views
Most efficient way to insert into ordered sequence
I have a dashboard like interface, that can have many tabs. There can be as many or as few tabs as the user likes, with the user being allowed to re order them as they wish. Exactly like browsers do.
...
2
votes
1answer
236 views
User data storage
I am writing my own website where users sign up. It then saves that data in an array. I want to know if this is effective or if there are better ways to do it.
...
1
vote
2answers
89 views
Same function but use different array data
I have these two carousels that randomly pick up pictures. [fiddle] Each of them picks up pictures and links from their own different inner array. It works fine as it is, but I was just wondering if ...
1
vote
3answers
271 views
Complex data structure organization in javascript?
Upon suggestion in the original question within stackoverflow, I'm bringing this question here.
Question Explained:
In a website that I built, I used complex multidimensional arrays to organize a ...
1
vote
2answers
106 views
Help me condense a series of lengthy javascript conditional arrays
I'm not too used to working with arrays in javascript, so was wondering if there is a good way to condense this down.
Any pointers much appreciated!
you can see it in action @ ...
1
vote
2answers
839 views
Javascript querystring to object conversion
The below code converts the window.location.search querystring into a JavaScript object. In particular, if a key occurs more than once the resulting value in the object will be an array. Please feel ...
1
vote
1answer
72 views
Declaring arrays knowing their maximum size
I know the maximum array size is 6. So what is the best practice to declare an array?
In the following code I used it like this:
...
1
vote
1answer
53 views
Optimize jQuery code includes autocomplete function for different input box with different autocomplete content
I have this code below for autocomplete feature of several inputTextbox. The input box also share same class".wikiInput". When user typed something in either of them, a relevant autocomplete dropdown ...
1
vote
3answers
671 views
Optimize Array.indexOf
How can I optimize checking a value in recursion before operating on it? I'm using Array.indexOf (this is Javascript)
...
1
vote
1answer
38 views
Find-and-replace optimization
I'm looking for some JavaScript code improvement and optimization. Is it possible to optimize this block of code (for example, remove double array loop)?
...
1
vote
1answer
844 views
Testing if numbers in the array can be added up to equal the largest number in the array
Okay, here's a challenge at Coderbyte that completely stumped me. I came up with a solution, but I know it is flawed.
Have the function ArrayAdditionI(arr) ...
1
vote
1answer
223 views
Turning multiple PHP arrays into one array ready for conversion to Javascript
I am creating a multiple choice quiz game with PHP and Javascript. Questions can have 2 to 6 answers. I have been using the PHP queries in the code below to get arrays of the questions of a quiz, and ...
1
vote
1answer
93 views
Shortening a webshop page
I am making a simple webshop page where I need to add a couple of products (and their prices). The shop consists of less than 10 products so therefore I decided to build my own solution since it is ...
1
vote
1answer
891 views
Change URL on select change
I've made a method, which inserts a new query parameter, when the value of a select changes, then reloads the page. I've had enough of URL jQuery hax, so I figured it would be a great idea to put the ...
1
vote
0answers
44 views
Numbers as javascript object property name? [closed]
I have encountered following construct (with changed values):
var something = {
1: "one thing",
2: "second thing",
3: "third thing"
};
and it is ...
1
vote
1answer
24 views
Find the object that contains title1-2
I use jQuery and underscore.js, I have title1-2 and I would like to have the action corresponding.
...
0
votes
2answers
48 views
Trying to convert an extended Array.prototype to a function
I got a random image rotator working by using the following script (demo). But I was told that it is a bad practice to extend Array.prototype. And it does. It ...
0
votes
2answers
298 views
Improve speed of object-to-html transform in javascript?
I have a rather large javascript array of objects that I am transforming into an HTML table. Each object in the array looks like:
...
0
votes
1answer
294 views
-1
votes
1answer
61 views
Box(x,y,X,Y), box(x,X,y,Y), box(x,w,y,h), box(x,y,w,h) or box(fromPos,toPos)? [closed]
Say you are representing a box, or creating a function that slices a 2d array, or whatever. How do you represent it?