Boolean expressions that can involve logical operators, used for branching execution paths, which increases cyclomatic complexity.

learn more… | top users | synonyms (2)

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 ...
11
votes
6answers
3k views

Writing the condition x <= y AND x > 0

My current condition is written as follows: ...
7
votes
6answers
425 views

Conditionals for time specific data

This is a fun piece. I have this block of code here: ...
4
votes
2answers
77 views

Marking a new dataTable row as consumed or cancelled

This is working code from a dataTable, which shows the function executed after the row is created: ...
0
votes
1answer
117 views

Processing selected and deselected elements

I think that this code is very bad because it does not agree with DRY principle. Can you advise me how to improve it? ...
2
votes
1answer
159 views

Rendering different view classes based on the value of a string

Here I'm instantiating different classes based on the value of a type property. This type property will determine what view is ...
-1
votes
1answer
52 views

Simple JavaScript Ternary

I need to set unit's exhaust. A unit might have a ...
2
votes
1answer
38 views

Converting any CSS colour to RGB(a)

For a plugin I'm writing in jQuery I have two optional parameters. For each parameter I do a check for its value. However, I'm curious if I can't write it shorter. Here is the fiddle and here's the ...
2
votes
1answer
68 views

Intercept URL containing values or not

I need to intercept a URL and go outside the WebView if the URL contains MAPS or DOCUMENTS ...
2
votes
1answer
45 views

Fields are required, except if all fields are empty

I have a group of four inputs, the first three are required, the fourth is optional. $fieldA $fieldB $fieldC $fieldD #Optional So to validate the inputs, I ...
-4
votes
1answer
59 views

Determining request status

This code gets request status based on request type and some mapping info. I'm wondering if there is a way to write nice conditional expressions in if statement. Expression should test if ...
-1
votes
1answer
61 views

Tried to change a if-else condition, but can it be better?

I recently came across this code snippet, and I have tried to change it. ...
6
votes
2answers
56 views

Handling calculator keypresses

I've added decimal (floating point) functionality to my calculator implementation; it's working but I'm having trouble making it more concise and less ugly. I'm trying to use the same method to ...
5
votes
2answers
85 views

Forming a dictionary where all values are only conditionally set

I have lots of dictionary keys with conditional values, ternary in this case: ...
4
votes
5answers
238 views

Class that represents a conditional expression

I have a class with which I want to persist a conditional expression: boolean x = a [GT] i I am only concerned with the ...
-1
votes
2answers
103 views

Validating input data

How can I simplify this? ...
1
vote
2answers
152 views

Seemingly redundant conditionals…or not?

I'm working on some code that has the following pattern of conditionals inside it. It doesn't look great, but it doesn't look terrible. Please, shed some light on the underlying reason this is not ...
3
votes
2answers
73 views

Composing terminal control sequences

I've seen everybody claims the nested ternary to be an evil even when an operation couldn't be written with switch-case; and here's even more, my code could be easily written with switch-case ...
1
vote
1answer
196 views

Changing DICOM tags using dcm4che

I am stuck on a piece of code that I have written that uses dcm4che. I have made a whole heap of nested ifs and I want to find a way to convert to a switch-case (problem being I have no way of ...
4
votes
2answers
66 views
2
votes
3answers
1k views

Filtering a list based on a value

Based on dropdown value and search text I need to filter a list and return. Method 1 ...
1
vote
1answer
120 views

Filtering a list based on conditions

I'm currently filtering a list based on several conditions, which may or may not be present: ...
6
votes
2answers
646 views
1
vote
1answer
37 views

A shorter way for getting variables

I have the following piece of code in my project, and that a few times: ...
8
votes
3answers
296 views

“Alien” distinguisher

I am practicing some simple Java coding problems in an attempt to learn while doing them. I would like to know if my code is redundant/is there an easier way to accomplish the same thing? Question: ...
5
votes
1answer
79 views

Effective use of branch prediction in terrain generator

I am trying to learn how branch optimization works. For an experiment, I have a recursive fractal terrain generation and I have moved all if statements to binary ...
3
votes
2answers
214 views

Multiple attempts to find the best icon

I have a series if statements where I am trying to find the highest resolution file in an set of files. Is there a way that I can refactor this code to be shorter and or cleaner? ...
6
votes
1answer
803 views

Cash Register Challenge

Challenge: Design a cash register program Specifications: Your register currently has the following bills/coins within it: 'PENNY': .01, 'NICKEL': .05, 'DIME': .10, 'QUARTER': .25, ...
1
vote
1answer
65 views

Faking a pass method when building an array

Ruby doesn't have a pass method to 'do nothing' the way Python does - if I want a ternary statement to do something on true, but nothing on false (as in the code below) is it bad practice in Ruby to ...
4
votes
1answer
65 views

Executing a list of tasks from a database

I have a list of tasks I get from my database (as strings) and then execute. However I'm uncertain on how to implement this correctly. Currently I have implemented this in the following way: ...
3
votes
3answers
101 views

Converting a state from hash into a JavaScript object

This code gets a state from a query string hash part, converts the hash part to a JavaScript object and then tries to get a view, ...
8
votes
3answers
564 views

Writing multiple if tags that compare two variables

I am a beginner in C# coding, and I was trying to compare two int variables: ...
4
votes
4answers
843 views

Truncate String to target length using only whole words

I've got a bit of code that I'm wanting to tidy up. The aim is to take a String that consists of multiple words connected by a separator (It's produced using ...
10
votes
2answers
164 views

Refilling a Bejeweled Board

When you start thinking about designing a Match 3 type game, you realize that there are a great many ways to structure the rules. In this particular variant, the direction that the player swipes the ...
2
votes
1answer
48 views

Condensing multiple conditionals into function

I feel like I'm repeating a ton of code here and there's got to be a better way to do this but am just completely spacing right now. I basically have an else if ...
5
votes
2answers
122 views

Concisely adding values in a loop to a column

In my data frame I assign values to the column Register by checking another column (Source) for specific values. Based on those values, the output in Register changes. I am relatively new to R, but I ...
12
votes
1answer
134 views

Board Evaluator for Bejeweled Clone

I've been prototyping a Match 3 game (Bejeweled clone) because I have an interesting concept for one, and because it is good practice. One key aspect of my version is that the matches must contain ...
3
votes
2answers
45 views
5
votes
5answers
341 views

Extracting the location for a page with fewer conditionals

I've been given the job of trying to reduce the line count for a file that helps generate a PDF for a web app. The class itself is pdfHelper, and contains a number ...
3
votes
3answers
193 views

Parsing argument list specifying a player to be added

I want to start off by saying sorry, I wasn't able to search for this problem as I couldn't exactly describe it myself. I have a series of if-statements to account for each scenario. As you can see ...
3
votes
2answers
204 views

Hide / Show panels depending of value of a dropdown

According to the value of a dropdown menu I have to show/hide two panels. For option 'derive' and 'reject' I should show the comment panel, and just for the 'derive' panel I should also show a ...
6
votes
2answers
77 views

Finding the Greatest Integer and Ties

I'm trying to find the greatest integer of four integers and its ties. I used the following code. Is there anyway to simplify this? ...
6
votes
2answers
537 views

Javascript condition optimization

Can the following condition be optimized/simplified ? ...
7
votes
1answer
138 views

Multiplayer bowling in Ruby (follow-up: injection, single responsibility)

This is a multiplayer bowling simulator in Ruby. It allows for variable skill levels, and produces weighted random results for each player's rolls based on those skill settings. This is a complete ...
12
votes
1answer
155 views

Multiplayer bowling in Ruby, with variable skill

This is a multiplayer bowling simulator in Ruby. It allows for variable skill levels, and produces weighted random results for each roll based on those skill settings. The methods are grouped in four ...
1
vote
4answers
430 views

Creating a grid in HTML from a database search

I have a little piece of code that is a little bit unoptimized and need some help with optimization in this case. The procedure is to search in a database using "Conditions/Condicao" and create a ...
2
votes
1answer
54 views

Conditional statements with doctor and patient information

I'm focusing on trying to write clean, modular Python 2.7.5 code. ...
19
votes
3answers
2k views

Adding a course to one of 8 periods

I have this rather ghastly if statement and I'm sure there is a way to condense it, but I don't really know how. I was told a ...
11
votes
4answers
1k views

Writing null-safe code to set form values

I will ask my question using the following example: HTML ...
1
vote
1answer
70 views

Conditional AND statement- which is more readable?

Does this function automationStatusIsSuccessful = (data) -> data.Automation.Status isnt "FAILED" and data.Automation.Status isnt "COMPLETEDWITHERROR"` ...