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
0answers
14 views
Asynchronous Conditional in Javascript
I'm trying to figure out the most elegant solution to do the following asynchronously using JavaScript (specifically node):
Given a destination file name, check if it is a directory
If it is a ...
2
votes
1answer
24 views
DRY rule and Accesing function within function JavaScript
I've asked this question recently on Stack Overflow but I was advised to look here, so there goes...
I got this piece of code below which is not DRY. What i want to do is to cut it,so everything ...
2
votes
2answers
40 views
Sieve of Eratosthenes JavaScript implementation - performance very slow over a certain number
I've been playing around with the code challenges on projecteuler.net. A few of them involve prime numbers, so I've created a function to find them based on the sieve of Eratosthenes.
It works fine, ...
0
votes
0answers
8 views
I am having trouble styling my map [on hold]
I have 2 google maps that I want to add to my page, they show up fine but I can't style them, what am I doing wrong?
here is the code:
...
2
votes
1answer
18 views
Summing 3 jQuery modal dialog functions
I am getting better with jquery day by day, but there are still things I don't know how to sum up several functions to reduce some code.
So I am using three jquery modal dialog popups and I have ...
1
vote
0answers
10 views
Pagination handlebars helper
I've build a handlebars helper that takes n total pages and currentPage and returns the HTML for the page number links, skipping ...
1
vote
1answer
15 views
Removing duplication in AngularJS Factory
I have multiple API calls so I created a service however I would like to find a way to remove the duplication
...
0
votes
0answers
10 views
4
votes
0answers
36 views
Xonix game in JavaScript
This is my very first program in JavaScript. I am trying to teach myself from JavaScript: The Definitive Guide, 6th Edition.
The code is also available on my bitbucket.
I decided to remake the ...
7
votes
3answers
59 views
Project Euler #8 - Largest product in a sequence
I've just finished Project Euler Problem 8, which ask for the greatest product of any sequence of 13 consecutive digits in a given string.
I wonder if there's something that could be improved.
...
0
votes
0answers
12 views
Testing a UI related revealing module
When I write my JavaScript modules I tend to keep a lot of methods private in an IIFE. A simplified example below:
...
1
vote
1answer
88 views
Checking that a filename does not end with “Com.js”
I'm fairly new to JavaScript and I wonder if there is a way to write this function shorter and better?
...
2
votes
0answers
10 views
Using one service ($http) on all the controllers angularjs
I have recently started working on angular.js and I like it. I have decided to use a single controller per view. I use the json data from the backend. As my work is ...
-2
votes
0answers
11 views
Implementing Scanline Algorithm [on hold]
I'm trying to implement a scan line filling algorithm for random triangles given 3 points as arrays and a color. I'm getting some weird results. Please ignore the optimization of the code, I'm just ...
3
votes
0answers
15 views
Optimization for better response time to use in analytics application
We are trying to use NodeJS for analytics. The following code gets the parameter from a URL and dumps it into a flat file. Is there any way to optimize it to get better response time?
...
1
vote
0answers
18 views
2
votes
0answers
27 views
Create one function instead of two bootstrap modal
I have a form that reads a JSON file for default wrong answers to be applied to a 'summary div' at the end of the form.
I wondered if I could make these two functions one somehow?
It is a bootstrap ...
3
votes
0answers
11 views
Salsa20 stream cipher
I have been implementing Salsa20 by studying the design and specification. I have made sure to unit test every function along the way and match the outputs against the test vectors in the spec. I am ...
-1
votes
0answers
32 views
Radial Tree d3 wrapping text [on hold]
The below is a modified code taken from the link http://bl.ocks.org/mbostock/7555321 which I am using in my project. In the input json file which looks like the below
...
4
votes
1answer
40 views
Full web app utilizing HTML, CSS, and JavaScript
Having started a new software dev role recently I'm in the process of developing my first full web app project using the following stack HTML + CSS + JavaScript + PHP.
I'm new in terms of applying ...
1
vote
0answers
21 views
Python DefaultDict implementation in JavaScript
I found Python's default dict and ordered dict incredibly useful, hence I attempted an implementation in JS. As JavaScript objects only supports string as key, it is not as powerful as the Python ...
0
votes
0answers
31 views
Change color of link if radio button is not checked
I have created an online exam system in PHP and JavaScript. In the HTML page, my questions are fetched from the database. If any question is unanswered or the radio button is unchecked, then the ...
0
votes
0answers
22 views
Module based todo list [on hold]
This is my todo list based on the Module Pattern. This is working fine and just want to know two things.
Can my code be simplified? Once I've added a list, if I refresh the page, then these lists are ...
1
vote
2answers
45 views
Alternate for nested Ajax requests
I have one button on clicking I need multiple things need to be done, so I went for AJAX and PHP:
...
3
votes
2answers
54 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 ...
0
votes
1answer
13 views
Creating object Nodes an easier way
I am required to create a bunch of object nodes to an object:
...
3
votes
0answers
35 views
How can I speed up the reading and writing of pixels of BufferedImages?
I'm working on a project that takes in a video file and does some image processing on each individual frame. The first step in that processing is to take each source frame and generate three ...
1
vote
2answers
20 views
Handling with the 'error' parameter inside a callback function in node.js
I have multiple controllers and every controller has this error handler:
if (error) {
res.render('error', {
error: error
});
}
Sometimes I have more ...
4
votes
1answer
284 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 ...
2
votes
1answer
55 views
Changing background colour
I am currently changing the background colour of a sidebar each time a menu item is clicked using the following code:
...
0
votes
0answers
31 views
2
votes
1answer
42 views
Method for parsing floats and adding totals
My intention is to create a nice DRY method (add) which will take care of parsing floats and adding totals internally and will be called by other methods.
I feel ...
-1
votes
0answers
26 views
JavaScript ForEach function [closed]
Is this a good forEach-function? Is there something important I missed or is there a smarter/shorter way to do it?
...
0
votes
1answer
37 views
Implementing Command Pattern - How to make more readable if else statements for commands? [closed]
I have a method, that execute some operations on a passed object.
Accordingly to the object type (cmd.declaredClass) I need to run some specif logic.
The execute ...
2
votes
1answer
33 views
Assembling a json object from an array
Is there a way to make this code shorter and more succinct? Thanks
My objective is to:
Take an array of objects (someArray)
Use get() to get one specific ...
2
votes
1answer
73 views
Notepad5, a simple HTML5, JavaScript notepad webapp
I made a simple notepad webapp, called Notepad5. You can use it to make notes while browsing the web and don't want to open up a separate application or extension to put the notes down and don't want ...
0
votes
1answer
23 views
Natural sorting/comparing algorithm in TypeScript
This code sorts string that may contain numbers in natural order, that's it, "item 2" comes before than "item 10". It currently ignores case. I plan to implement options to handle case sensitivity and ...
3
votes
1answer
28 views
JavaScript/jQuery DatePicker
I created some functionality for JavaScript datepicker.
I'm trying to store a value in the datepicker with the selected month along with which half it is. To do ...
3
votes
0answers
24 views
Custom dropdown selector
I'm working on improving my knowledge of OOP in JS. I just created this custom dropdown selector. It's working nicely, but I'm not super happy about the Filter ...
2
votes
2answers
46 views
Pulling data from different JSON files
I have a controller that pulls gets data from two different JSON files. One of the calls loadProducts happens when the controller is initiated. The other one, ...
0
votes
0answers
14 views
iterate through array with some undefined results [closed]
I'm iterating through array ,no errors found, but when i check the console, I get, 2 undefined results and it's pointing to the for loop code block,
...
2
votes
2answers
38 views
Quickly filter an object by keys
I am trying to optimize an object filter function. Given an array of keys, I need to filter an object. I feel that creating a new object each time may degrade performance. Is there a way to mock the ...
0
votes
1answer
19 views
Using app.use only in routes that start with /admin
I have several routes, and I need Facebook authentication only in the routes that start with /admin:
...
2
votes
2answers
81 views
Diamond kata in JavaScript
I'm just starting to learn JavaScript. I implemented the Diamond kata, and I would appreciate if anybody could give me some feedback. I'm particularly concerned about learning the most 'idiomatic' way ...
0
votes
0answers
14 views
jQuery cookie scroll position
I'm using jquery and cookie.jquery to remember the scroll position. Is there anything I can do to improve my code? Thanks!
...
0
votes
0answers
18 views
String Hashing Function using JavaScript [closed]
On Line 5, I wanted to convert key+1 from a string to a number without using the JavaScript functions parseInt() or ...
1
vote
2answers
33 views
Work out if a string is “fieldname” or “tablename.fieldname”, and assign variables
Is there a neater way to write this code?
...
4
votes
2answers
79 views
Press any login button on any site
I'm working on a script that will be able to press the login button on any site for an app I'm working on. I have it working (still a few edge cases to work out such as multiple submit buttons and ...
3
votes
0answers
58 views
Another attempt of “real private” methods in JS
URL: http://jsfiddle.net/rabbit_aaron/ve7deecw/
This is again, a JUST FOR FUN project. In this attempt, I use a closure instead of validating caller to ensure only member methods can access private ...
-1
votes
1answer
19 views
Accordion/collapsible
The code I wrote to do this effect stays "fixed" on top or on bottom. I did it the manual hard-coded way and wanted some advice on the best way to write something like this.
jsFiddle
...