ECMAScript (commonly referred to as JavaScript) is primarily used for scripting web-pages but also has several embedded forms and stand-alone interpreters / JIT engines. Use this tag for questions regarding ECMAScript 5 or 6 and its dialects / implementations: JavaScript, JScript, etc., excluding ...
6
votes
3answers
130 views
Finding the largest averaged array
Sometimes the best way to teach is show what you feel is a shiny approach instead of letting a student muddle through coding and potentially loose a future brilliant coder.
This is what I would show ...
-2
votes
0answers
9 views
Chrome and IE compatibility [on hold]
I wrote a program using HTML/JavaScript to read an xml file and output the data on that file to a table. It runs fine on Google Chrome, but nothing pops up on IE. I try checking for errors giving me ...
3
votes
1answer
28 views
Count frequency of words in a string returning list of unique words sorted by frequency in descending order
I have the following solution but I am trying to optimize it to run in O(n) time, any thoughts?
I first split the string removing any non-alphanumeric characters, then split the words using spaces ...
5
votes
2answers
166 views
Simple validation script
I'm playing about with JavaScript and wanted to create a simple validation script.
It works ok but is a bit clunky. How could I improve it?
...
1
vote
1answer
33 views
API factory for a realtime chat site
I was told I'm using factories wrong, but I'm not so sure. Any ideas? (I know I should be using GET; I've only just noticed that)
...
2
votes
1answer
43 views
jQuery and CSS3 slideshow
I have built a slideshow using jQuery and CSS3.
jQuery is used to trigger class changes (.slide1, .slide2 ...) on the slide container (...
5
votes
2answers
32 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
0answers
13 views
-7
votes
0answers
33 views
How to make this a more simpler version? i.e. more beautiful for my proofessor [on hold]
give the avarage of the 2 arrays, and the spit out the larger of the 2. This is what i have
...
-6
votes
0answers
16 views
how to take 2 arrays average and return the larger one [on hold]
This is my code so far,
i keep getting "first" when the answer is "second"
...
1
vote
1answer
25 views
Populate dropdown B on selection in dropdown A
On selection from drop-down A (HTML select) I need to populate another "sub"-dropdown with a different list of values. For instance, on selection of country in ...
2
votes
1answer
33 views
Cordova file management
I am making an application using Phonegap where users can select and share files. When the user selects it, even if it goes offline or closes the app, I should upload it back to the server, so I need ...
2
votes
1answer
39 views
Changing background with JavaScript
I am in the process of learning JS and I constantly have feeling that my code is bloat and not optimal.
I built this simple DEMO of background changing on click. Can somebody tell me if this is good ...
0
votes
0answers
35 views
Ajax Responses and from Rails Controllers into a View [on hold]
I've been banging my head against the wall all day and I wonder if I'm barking up the wrong tree with my approach.
I have a Controller that Handles my Amazon API search requests and returns an Array ...
0
votes
1answer
55 views
Full counting sort on HackerRank [on hold]
This is the full counting sort (CountingSort4) challenge on HackerRank.
I've gotten it to the point where it passes every test case except the final one. I believe my algorithm is timing out due to ...
2
votes
1answer
53 views
Expose only desired functions to 3rd party plugins in JavaScript
I tried to build a solution to dynamically load JS code, but to only expose predefined functions. Is this the correct approach? Is there any Method to execute arbitrary code if I put all my code ...
8
votes
2answers
497 views
Determining if a check box has been checked or not
I have a block of code that checks to see if a check box is checked or not, and assigns a value to a variable for saving to a MySQL table. There are approximately 8 of these boxes.
...
6
votes
1answer
70 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 ...
2
votes
1answer
41 views
3 textboxes with multiple value combinations to one output
I would like if someone who has more experience in JavaScript reviewed this. I went through and tried to minimize this as much as possible, but I still feel this could be smaller and more compact.
I ...
5
votes
0answers
29 views
Metalsmith plugin for stripping UTF8 BOM from files
I've been developing a metalsmith static site and I came across an issue where Visual Studio was automatically adding a BOM to the pages.
I wrote the following plugin for metalsmith (it needs to be ...
0
votes
0answers
48 views
How to handle state in Angular?
I am working on a project in Angular where I have a number of similar data objects. When you click on anyone of them it's state and amount of data shown will change. All of the objects start in the ...
3
votes
2answers
47 views
Multiple uses of $window.scroll
I'm using $window.scroll twice in a jQuery script for different uses. Should I try and combine them?
...
-4
votes
0answers
27 views
Div not showing properly [on hold]
Here: http://www.doublecentre.org/continue.html
you see two collumns, the lower one seems not to show itself properly.
It appears when you scroll down.
can anyone help me?
2
votes
1answer
68 views
Transforming complex strings into simple arrays
Some time ago I wrote a series of functions for turning a string of user information from multiple users an array containing the information needed: Name, username and location. The raw ...
7
votes
1answer
47 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':
...
-1
votes
0answers
37 views
Best practices for naming bool variables [closed]
Use is and has prefixes for bool variables in singular form.
For example, isNotNull, ...
1
vote
1answer
38 views
Managing JS assets
My main concern in this script is the 'js' task. Each time I change 'frontend.js' I concat and minify 'jquery.js', 'bootstrap.js', and frontend.js. I'm only really editing one file, yet on every save ...
2
votes
0answers
23 views
Bookmark application AngularJS controller complexity
I am working on a personal project for managing one's Pinboard bookmarks. Since this is already quite a big project, I am not sure if my question fits the guidelines. My main concern is with the ...
2
votes
0answers
13 views
RESTful API parsing DBF data HSET in Redis
I have this working code, but would like your review:
sync.coffe
...
-3
votes
1answer
26 views
Using a for loop to get multiple values that mean the same thing
How would I clean up this code? Would I put it in a for loop and make it loop through and set the rand2, rand3, ...
0
votes
0answers
34 views
Detect image in viewpoint of browser window then show image
I am working on a web project and am trying to create a way to detect when an image is in viewpoint of the browser window then load/show the image. Since there are some rather large image that are ...
2
votes
2answers
56 views
AJAX call to make an HTTP request
I am using node.js with express. There is a button that the user can click, and doing so calls this method on the server:
...
4
votes
1answer
81 views
Fictional Hotel Website
I've made a fictional hotel website that shows you hotel details when you click on a button.
jsFiddle
...
-1
votes
0answers
28 views
Pass more than one value in event parameter on jQuery On method [closed]
I´m doing a code to make <p:rowEditor> in Primefaces have a hint.
I did it
...
1
vote
1answer
50 views
Auto-populating user info from database
Auto populate user info from database when user inputs employee number. The same applies when the user inputs name/extension/mobile/email/
Some code is duplicated. Is there any way to make it ...
-2
votes
0answers
16 views
Javascript: How do I append a string to search query only once? [closed]
In this case, Let's take Google as example:
The code is JScript .NET, which is basically a .NET version of Javascript.Regardless of language, Anyone with appending type of skill can answer my ...
-1
votes
0answers
26 views
Positioned elements acting weird [closed]
I'm looking for some tips on how to properly organize my code so I don't run into as many errors as I have been lately. One of my problems right now is that my elements are positioning weirdly. My ...
5
votes
0answers
59 views
PubSub and two-way data binding
I looked up how to use the PubSub pattern in JS and came across a few articles. I wanted to have two way data binding, so when a one of an Object's Properties value was set, it would update x number ...
4
votes
1answer
49 views
Animating a div element
I would like to see how would you write this code for best practices, it will help me to learn from you.
This is my jQuery code I use on scroll event to addClass and animate div element.
...
3
votes
2answers
41 views
Null checks in user validation
I would like to know an alternative, more elegant way to write the following method. I am especially not enthusiastic of the nested if statement.
...
11
votes
3answers
846 views
Basic Terrain Generator - KhanAcademy
I'm new to JavaScript, and I've been learning off Khanacademy. I wrote the following basic terrain generator and I'm wondering if it could use any improvements. Here's the code:
...
1
vote
1answer
46 views
jQuery Widget - Progress Tracker
This is a follow up on JS Progress Bar Widget
I've rewritten it as a jQuery Widget Factory widget, attempting to follow that standard as much possible and fixing the various problems pointed out in ...
2
votes
0answers
18 views
BST remove implementation
As practise, I implemented a BST and also the remove() method, but I figured I always have to check if the node being deleted is coming from the left child or the ...
4
votes
1answer
46 views
Character and word count functionality
I have this JS that has a lot of redundant functionality, and it works but looks unseemly.
I would love some assistance with making this more DRY (Don't Repeat Yourself):
...
2
votes
1answer
36 views
Mapping object values from one object to another
I have an object called defaultOptions and a function that accepts as an argument an object called newValues meant to override ...
2
votes
1answer
27 views
Adding a class to an element in a plugin
I have the following code, and I just added a Class to the element that uses the plugin. I works perfectly, but I am wondering if there is a better way to do it.
...
2
votes
1answer
73 views
Separating values in string and returning them as comma separated string
I am iterating through a set of values that are in the following string format:
69;#Statements;#44;#Clarifications;#45;#Suggestions;
(fields with multiple values ...
1
vote
1answer
26 views
jQuery animations with only one callback
I'm aware of doing that 'magic' inside $.when(). How should I achieve same effect writing code more readable ? I read something about a $.Defferer() that I think should help but I don't know how to ...
1
vote
1answer
25 views
JavaScript and callback: apply an action on each element of a callback input
I'm quite new to js. I even don't know how to call this problem: apply an action on each element of a callback input, but the elements are actually an output..
I crash a lot on this situation: I have ...
1
vote
1answer
33 views
JavaScript / jQuery stopwatch
Just as a learning exercise, I set out making a stopwatch without looking up how to do it etc.
I know it will have been done many times before. I'm just looking for some feedback on what I should do ...