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 ...

learn more… | top users | synonyms

3
votes
2answers
36 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. ...
3
votes
0answers
14 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 ...
2
votes
1answer
28 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
78 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
23 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
43 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 ...
4
votes
2answers
103 views

Rock, Paper, Scissors, Lizard and Spock - Improving my answer

Today I saw an extremelly interesting question on the Rock, Paper, Scissors, Lizard and Spock game. And I've decided to take my swing at it. And I've written the following OOP implementation: ...
5
votes
1answer
63 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 ...
16
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
28 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
22 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
35 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

Transforming an array of arrays into an array with joins

I'm transforming this: ...
0
votes
0answers
28 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 ...
2
votes
2answers
34 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
55 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
10 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 ...
1
vote
0answers
21 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
12 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
45 views

jQuery Plugin - Sliding Tile Puzzle

I created a basic jQuery plugin to make a basic sliding tile puzzle. ...
0
votes
0answers
21 views

Extend date comparison function in Angular to take different dates as parameters [on hold]

I have an angular function which passes in two date objects and compares them returning one of two strings which are then passed as a class name to an html element. The idea being that if the date is ...
8
votes
2answers
87 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
94 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
23 views

Build a unique array of db fields

This is stripped down from a project I'm working on: ...
0
votes
1answer
14 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 ...
-1
votes
0answers
13 views

Switching a class between elements [closed]

I have a large table of text items. When I click on a class I would like to add a certain class to it, but also remove that class from previously clicked items. I don't want to have to scan through ...
5
votes
0answers
64 views

Multiple inheritance pattern for vehicle information

I wanted an easy way to augment objects, by adding functionality from any other object(s). More importantly, I needed a way to augment the object from multiple sources in a clean one-line solution. ...
4
votes
1answer
24 views

Gives a live view to a changing file on server

I have a file on my server which contains a running output of a script. This file is constantly changing and fluctuates in size between 0 - 1Mb. Now I want to take this file and make it viewable from ...
-4
votes
0answers
30 views

CSS class based image loader [closed]

I have a piece of code. Kindly write this in the best way so that it will work on all possible browsers. Specially I need best approach to write: ...
-2
votes
0answers
10 views

JS variable not being updated [migrated]

I've an issue with calling out JS variable in my HTML. It's simply not getting updated. The following code is palced in the header: ...
3
votes
0answers
54 views

Login to bank site and get balance and other details

I use this piece of JS code to login to my bank and get the balance. This code snippet works, but I wanted to know if I could make this code smaller, faster or if I could anything differently to ...
0
votes
0answers
18 views

Populate Select Dropdown from Data Model [closed]

Populating simple dropdown list with items from the data model using Knockout.js ...
4
votes
2answers
61 views

Lorem ipsum chat bot

I'm a web development student, and I made a chat bot that emulates an SMS app commonly found on smartphones, etc. It responds with random lorem ipsum text. I'm wondering if my functions are too long ...
9
votes
2answers
112 views

Simple function to verify if a number is integer

Sometimes, there's the need to verify if a given number is an integer or a decimal. Since JavaScript doesn't distinguish between both, I've made an extremelly basic function. ...
2
votes
0answers
34 views

Ember.js blog app architecture

I decided to create simple blog app by using Ember.js which should has the following interface For this purpose I created ...
2
votes
1answer
24 views

Navigational bar content built depending on login state

I created a login service which holds a boolean based on if a user is logged in or not. ...
1
vote
1answer
50 views

JavaScript accordion

I'm trying to refactor some code I wrote months ago when I used to use lots of anonymous functions. The way I'm trying to do it now is by taking all those functions and rewrite them within Object ...
-4
votes
0answers
24 views

Pass a String argument to a function in order to prevent redundant code [closed]

I have got used to pass an argument type to several JavaScript functions in order to prevent redundant code. For instance: ...
2
votes
1answer
66 views

Function to compare phone numbers

I got rejected in tech screen yesterday. I was asked to write a JavaScript function and send it over email. The question was(I have added the full question below). I have also added hiring manager's ...
1
vote
1answer
38 views

Angular directives

Can you give me tips about this code? I'm thinking it's very messy. ...
0
votes
0answers
16 views

Bootstrap alert plugin

I'm now venturing into the world of function writing. I have pieced this code together getting a head start from Dynamically create bootstrap alerts box through javascript. I have added animation on ...
6
votes
1answer
55 views

printf-style string formatter

As part of a larger project I'm working on, I've made a function that aims to replicate, as best as I can, the placeholder part of the console.log() function usable ...
3
votes
1answer
29 views

Userscript hiding boxes on linkedin

When looking at people you may know on LinkedIn (requires you to be logged in) there are sometimes some annoying boxes that are for people who are email contacts but not on LinkedIn. I don't want to ...
4
votes
1answer
51 views

McCarthy's Pub Beer Menu

I wrote a little bit of code in JavaScript that takes an array of objects and does some sorting, then outputs to an HTML page. I set a goal to do it without any frameworks, and in functional style on ...
0
votes
0answers
7 views

Angular controller to fetch information on conractors [sic] and projects

In my Angular controller, I am using 3 different functions to get the data. It works fine, but is there a way to simplify this? ...
3
votes
1answer
41 views

Checking tag colors

I have an array vs.tags which may contain hundreds of objects, and a smaller array coloredTags which only contains up to 3 ...
2
votes
2answers
31 views

Commute cost calculator

I wrote a simple javascript program that takes a user's input and calculates the cost of their commute. I feel like I'm repeating a lot of stuff though. How could I refactor this to make it cleaner ...
2
votes
1answer
23 views

Getting the character index of recurring substring

I created this function that allows you to declare a string, then multiple instances of a substring. This uses a hash map to keep track of strings that have already ...
3
votes
2answers
118 views

Mutually exclusive radio buttons

Here is a small code snippet I wrote that I feel is pretty naive. I copied the code directly from my project and renamed some ID/class names. I'd like to know how you could help to improve/refactor ...