5
votes
3answers
72 views

DRYing out a basic image slider

I built a very basic image slider, but I'm still having trouble refactoring. I caught myself reusing same code for clicking the previous/next buttons, selecting a slider dot, and the automated ...
8
votes
1answer
87 views

Reduce duplicate sequences

I am writing a copy paste detector using esprima.js and Hmm. This particular function checks a number of sequences and reduces them. Due to the parsing I might have 2 sequences with the same piece of ...
2
votes
1answer
111 views

Checking if variable is defined before accessing its properties [closed]

I didn't write this but I noticed it in our codebase at work. ...
5
votes
2answers
166 views

DRY + principle of least knowledge + MVC in JavaScript

Is there any way of improving this code? (Here's a JSFiddle with an example and comments) Example: A Hotel greeter can greet guests and accepts tips, but it's impossible to see the total of tips a ...
5
votes
1answer
241 views

Code seems repeated, except for the callback function

I've written some JavaScript code: ...
3
votes
1answer
69 views

Breaking after one of several string replaces occur

I have a script that matches a string against ~20 different regexs for the purpose of changing it. They are ordered and formed that the string will only ever match against one. How can I avoid ...
7
votes
7answers
790 views

DRY-ing jQuery code for portfolio site

I'm currently working on my portfolio site and it's all great, but I'm unsure how to DRY my jQuery. I'm repeating myself a lot in the jQuery and it's just messy. HTML: ...
4
votes
1answer
131 views

Are my filter functions DRY enough?

Here's a function I wrote - am I getting DRY about right? I could add another argument to paramFilter maybe, for even less reuse. Or have I gone too overboard as it ...
4
votes
2answers
381 views

Wait until all files are loaded asynchronously, then run code

I'm an experienced programmer but not too great at JavaScript so I'm looking to see if I'm doing this 'right'. I want to have several files loaded in (Ajax or really AJAJ) and, once loaded, run some ...
5
votes
3answers
179 views

jQuery Tab function

I have this script that I need to run a tab (jquery). Mainly I need to hide some div and add class (you sure have understood). How should it be written in a more elegant and readable? ...
10
votes
1answer
142 views

Tabbed navigation to hide and show pages

I'm new to jQuery and trying to learn how to refactor my bloated code to make it nicer and better maintainable. I have a tabbed navigation which I'm using jQuery to hide and show pages depending on ...
5
votes
1answer
65 views

Shorter way of writing my displayError() function?

Is there a way I can write this function with less code? jQuery ...
2
votes
2answers
104 views

Is there a simpler, more efficient way to write this function?

I see that there are quite some words that are appearing double or more times in my code. So I'm thinking there might be a more efficient way of writing this code, only I don't have the knowledge to ...
2
votes
2answers
108 views

How to simplify these jQuery lines?

I want to find a way to make a function from my code. I'll have more than 20 queries like this. It's time to make a function. :) ...
4
votes
2answers
78 views

Do I need to trim this jQuery code?

I had three multi-select boxes from this page. I want to customize each box so I simply repeat the code three times with different options: Check the fiddle ...
5
votes
1answer
46 views

remove redundance in compare-functions

I wrote some compare-functions that I pass to other methods in javascript: ...
11
votes
9answers
2k views

Is there a more succinct way of writing this simple JavaScript loop?

This seems a bit redundant to me, but I'm not sure of how else I might be able to write this. Normally I'd use a switch statement, but I don't think that'll work ...
4
votes
1answer
25 views

toggleSaveStream button template

I've got a view which has a corresponding template. The template looks something like like: ...
3
votes
1answer
44 views

Checking for a value on selectors

I've got some pretty simple validation that I'm working on, but it seems like I'm repeating myself a bunch of times. There has to be a better way of doing this. I'm simply checking if there is a value ...
3
votes
1answer
1k views

Sign-up wizard structure seems too repetitive

I think my current structure is way too repetitive. I feel like I must be missing something that would easily make this sign up wizard work far better. ...
1
vote
3answers
28 views

Is it possible to condense this code?

I have three functions, each assigned to an anchor tag which gets called onclick. Is there a way to condense this code? It seems redundant to have three function ...
6
votes
1answer
77 views

Pass in parameters instead of multiple functions

I can't quite figure out the best way to approach this. I have two jQuery objects that both are used to set cookies. I then parse the JSON and set a cookie that is either the users height or the users ...
7
votes
1answer
86 views

DRY multiple if statements used to show/hide elements based on slider value

I'm showing and hiding 4 svg paths based on the value of a slider, all is working as expected, but it still feels a little cumbersome. Does anyone know a way to "DRY" it out a little more? jsFiddle ...
10
votes
2answers
339 views

Monopoly game cards

This functionality is for a Monopoly board game. In particular, when the player lands on Chance or Community Chest, a random card is drawn with a particular set of instruction, a bonus could be paid ...
2
votes
2answers
262 views

Javascript DOM Override Review

I'm building an mini-app that will display when changes to the DOM have been made by javascript. I have all of the functions that I can think of listed in the code. Is there a way to consolidate the ...
1
vote
2answers
154 views

How can I achieve DRY principle in this code?

In the following piece of code I use the same trick three times. But cannot figure out how to write a common function that will do it for all of them. I know there is a toggle method in jQuery that ...
2
votes
2answers
172 views

Whats a better way to do these nested if statements?

I forgot to mention using the result of bar to calculate foo's value in the question I asked here. The function bar only needs to be called if conditionA is true. But when the result of bar ...
6
votes
3answers
395 views

What's a better (DRY) way to do this if statement?

The function bar only needs to be called if conditionA is true. But when the result of bar (...
2
votes
1answer
221 views

Cross-language Constants

Background Developing a web application that leverages multiple programming languages. The data flow resembles: Browser » PHP » PL/SQL » XML » XSLT » XHTML + JavaScript » Browser Using different ...
0
votes
1answer
53 views

Simplifying and improving (namely DRY) for flight info fetcher

I've put together this simple fetcher for text data (which I just copy and pasted from a flight info website) - it takes in text data, and spits out an array of objects containing values for each ...
2
votes
2answers
148 views

Can someone help me DRY up these jQuery each loops?

I just posted this on the Stack Exchange, but was told I should post it here: ...
2
votes
2answers
410 views

Avatar creator form

I'm making an avatar creator with jQuery where users can select and change hair, eye and skin colour. The page is a form with different values and when the user clicks on the form options the values ...
3
votes
2answers
90 views

JavaScript optimization

I'm pretty sure there's a way to make this "3 times" duplicated code into only one. Any idea how to do this? ...
1
vote
1answer
93 views

Shortening a webshop page

I am making a simple webshop page where I need to add a couple of products (and their prices). The shop consists of less than 10 products so therefore I decided to build my own solution since it is ...
2
votes
1answer
253 views

Is there a better way to do a Luhn check?

I feel like I should not be duplicating the code to gather the credit card number, but I am not sure how best to do it. Any suggestions? ...
2
votes
3answers
2k views

Simple jQuery validation script works but it uses a ton of if/else statements

I've a jQuery validation script to check all form fields for a valid value and prevent form submission and display an error message if any fields fail. It was requested that the validation script not ...
5
votes
3answers
308 views

How can I make this code more DRY?

This code is for a simple language quiz. It fetches two words and related audio files via a JSON call, presents the user with an image that matches one of the words, and challenges the user to make ...
1
vote
1answer
817 views

Javascript get item in object code

So I have some Javascript code that resembles the following: ...