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 ...
2
votes
2answers
13 views
Passing JSON object through loop to be used in jQuery Dialog
I'm wondering if there is a better (cleaner?) method than my current implementation. I'm currently encoding a PHP SimpleXMLObject (USPS Tracking API) to JSON and ...
3
votes
2answers
55 views
Greasemonkey Fantasy Football Script
I have the following Greasemonkey script that fetches some data from a Yahoo webpage and injects it into a webpage. It has the feature that it only fetches the data once per day instead of fetching it ...
13
votes
2answers
304 views
AngularJS - REST + Authentication service
I have a REST web service that uses OAuth 2 for authenticating and authorizing requests.
I have an endpoint, that when receiving the correct credentials, responds with an access token that will be ...
9
votes
3answers
544 views
Lights on: playing with buttons in Javascript
First play with the game a little bit, and it is quite fun (a little hard but very satisfying when you win, be sure to put it full page):
...
1
vote
5answers
39 views
Using jQuery to restyle page depending on window width
I currently have a javascript file that I'm using to fix the navagation on on a website I've built. The code is by no means 'DRY' though and I'd like to fix that issue so I'm not repeating myself. Any ...
4
votes
1answer
46 views
Disable Element If
This is a pretty straightforward library function I've got here. I've had to build it in to about 3 different forms but I never heard of this kind of function anywhere else.
I'm trying to make it as ...
6
votes
2answers
273 views
Updating the presentation of a credit card field as the card type becomes known
The goal here is to, add a credit card image, and remove all other credit card images, of a certain input field.
I had a even larger code, with a lot of addClass() and removeClass()... then, I shrink ...
6
votes
4answers
85 views
Simple number theory game, pt. 3
More refactoring based you guys' great feedback. This time around I worked on using global/local variables properly and efficiently, putting return values to use, renaming variables so that the code ...
4
votes
0answers
37 views
AngularJS inheriting from a base directive
I'm wrapping ui-select in my own directives to pre-configure and style it, as I need it for my app in different select widgets. They appear on many pages, for example ...
-3
votes
0answers
25 views
Lottery Code Validity [on hold]
I found this code for a lottery on a website for some free gifts and I was just curious, it didn't seem to be random. Could someone who knows javascript explain how this code picks a number?
...
2
votes
0answers
19 views
Using bind instead of promises or stacked callbacks
I've seen tutorials about node promises and such but not using bind. I feel like I can do lots of things this way and keep everything clean:
...
7
votes
2answers
80 views
Simpler number theory game
After receiving some awesome feedback in my first post yesterday, I was able to grasp the "building block" method of creating javascript in chunks and putting them together to create ...
2
votes
0answers
34 views
Organising a JavaScript file
I have a JavaScript (jQuery) 'init' file with various variables/event handlers and functions that are currently written in no particular order. I've read that it's good to organise these by declaring ...
0
votes
0answers
44 views
Initializing an AngularJS app
I've created code in each of my controllers and directives that calls an initer function in the main app.js module, the function just passes strings which are ...
3
votes
1answer
31 views
MVC partial views and AngularJS modules
I am using MVC+Angular. In MVC, I created partial views for search, listing, etc. I show them using:
...
3
votes
1answer
40 views
Pomodoro Timer via setInterval
I'm hoping for some input on if my code is DRY or how I could have made it more efficient. I am pretty new in terms of jQ/JavaScript and this took me far longer than I care to admit. I will post the ...
2
votes
0answers
39 views
Extremely redundant HTML templating
This is horrendous.
I'm using lodash's templating engine for this table. Here's the template for an individual record's row. I've got 5 different table and ...
4
votes
2answers
57 views
Modeling rainwater collection and cost
The following is a function that takes an area as an input and outputs some resulting calculations.
I thought an object was useful for creating multiple instances with different custom properties ...
10
votes
3answers
603 views
Simple number theory game
I just started JavaScript about a week ago. For my first project, my goal was to use my knowledge of basic JavaScript to create somewhat of a "thinking computer brain," so to speak. I wasn't focused ...
3
votes
2answers
46 views
MVC and Services
I'm writing and app in AngularJS and am learning about writing RESTful services. I also want to make sure that I'm understanding the MVC pattern correctly. In my code, this is my take on how I'm ...
-3
votes
0answers
23 views
explain matrix creation code [on hold]
Here is the original question where the user asks how to create an empty matrix. One of the answers is the following
...
2
votes
1answer
14 views
Saving and loading parts of configuration
I have a piece of code where I have string pairs (eg. 'a' and 'AA'), where both have their own unique ids. Id for first object is configured by user and second id is received at some point during ...
-2
votes
0answers
17 views
4
votes
1answer
35 views
Making my underscore template code more manageable
I currently have what seems to be a very overly complicated underscore template full of conditionals and as the data grows I'm worried the conditions are going to get more and more extreme. Can anyone ...
0
votes
1answer
19 views
Flattening a 2D array to use map/reduce
I have been trying to get better at functional programming, which includes understanding map/reduce. I wrote a function intended to fill an autocomplete with values. The challenge I was encountering ...
3
votes
2answers
57 views
Present waitlist dialog box if placement is full
I wrote an ugly mess of a JavaScript function that pops up a dialog box based on validation data, when a checkbox is clicked. I am wondering if it can be refactored somehow.
...
4
votes
1answer
44 views
Web-based test settings manager app
Background
I work at a company that makes hardware products. All the test settings are stored on the server so it updates all our test stands.
I'm currently working on a web-based app using ASP.NET ...
3
votes
1answer
40 views
Looping through nested arrays with creating new array from nested items
I have written this function but I am not so proud on it. I could use some help refactoring it.
Would recursion improve my code?
Data sample.
...
1
vote
2answers
86 views
Making equal-sized tabs to fill the full width of a box
How would you simplify the following block of jQuery code?
I use this in a tab-box to size the tabs to style the tabs to the full width of the box no matter if it's 2 or 10 tabs...
It works ...
1
vote
1answer
27 views
Synchronizing scrollbars, scrollTop and scroll event loops
I've been playing around synchronizing two scrollbars on a web application using JavaScript and jQuery (1.11.3). So far what I've been doing is any time a scroll event happens on one div, I use ...
3
votes
2answers
47 views
JavaScript solution for diagonal difference
hackerrank.com - diagonal difference:
Problem Statement
You are given a square matrix of size N×N. Calculate the absolute
difference of the sums across the two main diagonals.
Input ...
5
votes
2answers
146 views
Rock, Paper, Scissors, Lizard and Spock with OOP
Today I saw an extremely interesting question on the Rock, Paper, Scissors, Lizard and Spock game. I've decided to take my swing at it and I've written the following OOP implementation:
...
5
votes
1answer
64 views
Curry function with function constructor
Shall I make a curry function this way, or is it best to avoid Function constructor in all means? What I want to know is if this is "bad practice" and how else currying can be done. For instance, one ...
17
votes
6answers
3k views
Rock, Paper, Scissors, Lizard and Spock
I am currently done with this little Rock, Paper, Scissors, Lizard, Spock game in JavaScript. The game is working fine, but I am not pleased with the code. Is there a way to refactor these ...
5
votes
1answer
30 views
Hiding and Expanding Menus
I've created code for a menu system that can show / hide menus and submenus. Now I wonder if the structure of the code is good enough or if you find something that can be done better?
...
2
votes
1answer
24 views
Create an array of categories from comma-seperated text input
This code works just fine, but could obviously be more elegantly written.
The basic idea is to create an array of categories from a text input. The code splits up the text input by commas to create ...
0
votes
1answer
37 views
AngularJS to-do list controller
I am new to Angular. Am I following best practices here? I understand controllers should not do too much. My controller seems to have a lot of logic here. Can I do anything to improve it? It is just a ...
3
votes
1answer
40 views
0
votes
0answers
33 views
jQuery form validator
I am new to the world of jQuery plugins, I don't know why I didn't get into this sooner. What I have a working validator that validates bootstrap styled forms. What I have discovered is that the way ...
3
votes
2answers
37 views
Adding and removing PHP parameters on click
I'm trying to optimize this repetitive piece of code. I think I need to set subsection href as a variable and then figure out a way to merge the functions?
...
5
votes
1answer
59 views
JavaScript program to count lines of Java code
I've implemented a small program in JavaScript to count the number of lines of a string of java source code.
This was done for one of the Code Kata exercise: ...
1
vote
1answer
17 views
Shuffling and hiding views specified by parameters
In my Angular app, users click on different icons. When a user clicks on respective icon, I can show the icons gallery, as well shuffle the view.
Apart from this ...
2
votes
0answers
34 views
Share on social onclick using jQuery
I have the following code to share my website through some social networks when the user clicks some divs with the appropriate icons.
...
2
votes
0answers
14 views
Optimizing D3 Stream Graph Code
I have two javascript functions that generate a D3 Stream graph. I feel I may be excessively and unnecessarily iterating over my dataset to get it into the desired form.
How might I optimize or ...
5
votes
1answer
50 views
jQuery Plugin - Sliding Tile Puzzle
I created a basic jQuery plugin to make a basic sliding tile puzzle.
...
9
votes
3answers
117 views
HTML to Markdown converter
I've made a simple HTML→Markdown converter in Javascript and am looking for any feedback. For now, I've basically used Stack Exchange's /editing-help as a guide as ...
4
votes
2answers
100 views
Window timeout alert
How can I improve this window timeout alert code? I need to add it to some third-party master page and don't want to add a separate file for it.
It must be JS only and IE-8 supported.
jsFiddle
...
1
vote
0answers
15 views
Pulling data quickly from mongodb with node.js
I am currently struggling with a request I am making to my server that is taking more than 4 seconds!
I am using socket.io, express and mongoDB in the back end.
I cut out a lot of the cruft to ...
3
votes
0answers
24 views
0
votes
1answer
17 views
Node.js RethinkDB connection wrapper with built in retries
I wrote connection logic for a wrapper around RethinkDB in node.js. While it works, I know it can be cleaned up, and done in a better manner. Essentially the logic is start at the first host in ...