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 ...
3
votes
1answer
52 views
Toolbar using jQuery
I am a beginner in JavaScript and starting to understand jQuery. I've written a toolbar that uses jQuery. I've also put comments based on what I understand of how the code works, though through the ...
5
votes
1answer
68 views
An utterly pointless jQuery program
This is the first jQuery program I've written, and it doesn't do much, but I'd appreciate the feedback. Just click on the different colored buttons to do things.
Codepen
...
3
votes
1answer
127 views
Using $q in Angular JS to pass navigator geo JSON from factory to controller
This code is used to get the users location and deliver it as a resource to the controller. The aim is to have this data shared across multiple controllers in the application. So far this does deliver ...
4
votes
2answers
1k views
Flatten an array - loop or reduce?
Problem: Concat all sub-arrays of a given array.
Example input: [[0, 1], [2, 3], [4, 5]]
Example output: [0, 1, 2, 3, 4, 5]
...
4
votes
1answer
88 views
Removing popup notification, the dirty way
I'm new to coding and I am self-taught up to this point, so my scope for creativity is quite limited. As such I'm doing something in particular that I suspect isn't the "best" way of achieving this ...
2
votes
0answers
23 views
Comparison of sprite movement implementations
I've come up with two ways to do sprite movement with CreateJS, and I'm wondering if one is better than the other as far as performance and maintainability.
The player data is saved in a json file ...
1
vote
2answers
51 views
loadSmartConfig function
I am writing a conditional that checks two values, for several different scenarios.
What I am modifying is a series of objects, some of these objects are in arrays, and some are just arrays. I need ...
4
votes
1answer
26 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 ...
7
votes
1answer
176 views
Animations when navigation items are clicked
I'm a beginner in jQuery and am wondering how I could write the following code shorter, since I'm repeating a lot.
Working example
...
2
votes
0answers
32 views
1
vote
1answer
58 views
Best way to implement j_security login
I have a j_security login implemented but it's been giving me a lot of problems and wanted to know if there's anything that sticks out as incorrect or outright ...
0
votes
1answer
48 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 ...
1
vote
1answer
52 views
0
votes
2answers
5k views
Convert object array to hash map using lodash
Use Case
Fairly new to Lodash/Underscore. The use case is to convert an array of objects into a hash map where one property is the key and the other property is the value. Common case of using this ...
2
votes
1answer
37 views
Converting a string to a corresponding type in JavaScript
I need to convert a string value to its primitive type in JavaScript. Other values that are not of type String should just be returned.
Example:
String '...
0
votes
1answer
95 views
Output JavaScript object into HTML table of key-value pairs using jQuery
This function is meant to take an object, loop through the key-values and generate/build a HTML table at a particular ID:
...
2
votes
1answer
62 views
Minimalist accordion implementation using vanilla JavaScript
The following example is an accordion script in JavaScript that does not use jQuery. When I started looking for a simple solution to this requirement I did not accept the idea of having to use a ...
1
vote
2answers
205 views
JavaScript parameters - best practices for settings object/callback
I have the following function which runs as expected and is defined in the window object:
...
0
votes
0answers
13 views
Trying to print entire Kendo grid(with paging) at once. Trigger Print function(print only div) only after previous function has executed [on hold]
This is my First method which sets the page Size dynamically and takes data from a server. So takes a bit of time.
...
1
vote
1answer
40 views
Handling callbacks when doing async programming and dealing with scope
I'm using HapiJS to create a little backend for my side-project. In grabbing RSS feeds, I want to loop through my list of website URLs, grab the correct RSS links in the ...
0
votes
1answer
29 views
Consuming an API with authentication
I have created a library which consumes the Imgur API.
This is the main file.
...
1
vote
1answer
27 views
Return fake jqXHR from custom Ajax method
I have several methods that wrap the $.ajax() method and return its jqXHR, but I need to force fail before even calling the original ...
3
votes
1answer
43 views
My Google Maps Script v3
My Google Maps Script v2
I re-factored my code to be more OO.
Does it have any more room for improvement (naming, readability, oop, etc.)?
I'm importing ...
3
votes
1answer
59 views
Hide and show columns in an HTML table
Codepen Link
I've tried to Google, but there's no library that has an API to toggle table columns when clicked elsewhere on the page, so I've decided to do this:
...
0
votes
2answers
36 views
Display relevant contents if radio button is clicked using knockout.js
I have four radio buttons and I want to display relevant contents for each of them if they are clicked. I am using knockout.js for data binding.
Is there a better way to write the if statement ...
1
vote
1answer
100 views
Dealing with the need to pass the root view model down to the children
I tend to feel the need in my Knockout applications to pass along a reference of the root view model down to the sub view models. However, I don't like the fact that I then have a dependency that lies ...
0
votes
0answers
27 views
Service per Controller
We have a base module consuming the company API. In each app I've written almost always a service per controller. Because most controllers are specific to a entity (a single user, a single post, list ...
0
votes
1answer
10 views
Making events not trigger so often on a datatable with dc.js
I used this answer to make a table with datatables.net and dc.js. However, I detected a performance issue in this loop:
...
3
votes
1answer
121 views
Visual increment and decrement button controls in jQuery
I currently have a working implementation of a + and - tank level thingy (I don't really know what to call it). In which will be able to 'add' or 'remove' so-called 'liquid' from the container.
...
6
votes
4answers
334 views
Constructing a JavaScript slide
I am a newbie to native JavaScript and am pretty much coming to grips with the operators, etc. At the moment I am currently constructing a slide.
...
4
votes
1answer
106 views
Optimizing pagination of HTML tables
I'd like to share my implementation to you to confirm if it's a correct way to solve my problem. I have a list of products which have an attributes table and a description table (both in html_encoded ...
1
vote
1answer
24 views
Handling all error conditions on success or failure response
I'm working on a screen where I sent a request and I get response in two types.
One is success and contains the below format:
...
5
votes
0answers
52 views
Creating a Game Map
I'm trying to make a kind of Dungeon Keeper clone. I got the code up and running and even supporting touch events. But I don't think its as well optimized as it could be, so I am looking for help and ...
1
vote
1answer
35 views
Lodash chain implementation
I am mainly trying to avoid the nested forEach statements and am trying to move towards a lazy evaluation type solution.
jsFiddle
...
5
votes
1answer
327 views
2048 (game) solver 2.0
Follow-up of 2048 (game) solver
I improved the script, using standard search methods like expectimax. Now it goes easily to 2048, but not really further, the difference with the highly efficient ...
0
votes
4answers
37 views
Account disabled and deleted functions
I have the following functions that for the most part are utilizing much of the same code (except for the actual message). What are the possibilities, if there are any, for combining / reducing these ...
0
votes
1answer
30 views
Displaying information served on the client
I recently did a coding problem for an interview that unfortunately led me to not getting the position. So I figured I'd get the code reviewed by other professionals because after asking about the ...
12
votes
2answers
666 views
Checking conditions before allowing a play button to become visible
I have this code to check a couple conditions before allowing a play button to become visible. Is there anything to do to consolidate this code?
...
14
votes
4answers
3k views
Snake game with canvas element code
I created a classic snake game in the canvas element. I have not considered best practices when doing this, I just wanted to finish it first. Now it's time to improve the coding practice. You can ...
2
votes
4answers
87 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:
...
1
vote
0answers
17 views
Hybrid event model - comments wanted
I've tried out a hybrid type of event management model, combining elements of the addEventListener-type and the onEvent-type. What I don't like about the addEventListener model is that you have to ...
2
votes
2answers
238 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 ...
3
votes
2answers
49 views
My Google Maps Script v2
My Google Maps Script v1
Using the Google Maps JavaScript API v3.
Does my script have any room for improvement (naming, readability, oop, etc.)?
I'm going to pair it with some live time ...
0
votes
0answers
19 views
JavaScript rock paper scissors [closed]
So I'm trying to write a loop for the rock paper scissors game if the user chooses a word other than rock paper of scissors but this only works for rock. Does anyone have any ideas? Sorry if this is ...
0
votes
0answers
15 views
better way of writing javascript functions [duplicate]
I am a newbie to native javascript, i am pretty much coming to grips with the operators, etc. At the moment i am current constructing a slide. please view the code below.
...
2
votes
1answer
13k views
JQGrid Dynamic Columns and Server-Side paging , sorting, filtering etc
I have a requirement where I need to build a grid with dynamic columns. I am dealing with a large dataset so I would like to use server-side paging, sorting, filtering logic so that I render only a ...
6
votes
1answer
92 views
Check a collection of prices against an associated collection of minimum prices
I would like to find a more efficient way to solve this problem. My current implementation has 3 separate loops through the data.
I'm creating an algorithm to check a collection of prices against an ...
3
votes
1answer
147 views
Implementation of a unique collection
I am pretty new to JavaScript and learning the intricacies of this language. I wanted a unique collection which will overwrite while adding if an item already exists else add. Rest of the behavior ...
1
vote
1answer
55 views
Setting combined height and width viewport “breakpoints”
I'm using JavaScript to handle breakpoints in a single page, non-scrollable application. I want to do various things when changing viewports, such as fire off animations with a JavaScript animation ...
3
votes
1answer
988 views
Mongoose promise & error handling
I search for rails-like way of writing NodeJS code and it's more then hard to find the right way. The code quickly become bloated and unreadable. I would like my code to be as clean as possible.
...