Tagged Questions

A function (also called a procedure, method, subroutine, or routine) is a portion of code intended to carry out a single, specific task.

learn more… | top users | synonyms

0
votes
2answers
54 views

Pick a column for each row by column-header name

I am parsing a table: |-------| |Bar|Foo| |-------| | 5 | 6 | |'f'|'g'| | 1 | 8 | |_______| I've tried a number of ways of ...
0
votes
0answers
49 views

The Monty Hall Problem (with functions) [closed]

I have been asked to make a Monty Hall style program where there are 3 doors, one that has a prize behind it and the user has to guess which one. After he guesses, one door will be revealed and he ...
2
votes
1answer
40 views

Defining functions in Vigenere cipher

I'm trying to learn the process of defining/calling a (somewhat) complex function. I understand the main idea, and can do it on a small (simple) scale. A simple example: ...
3
votes
2answers
88 views

Cleaner structure for Battleships code

The code provided is working fine, but I would like to see if there is room for improvement for the code provided: ...
1
vote
1answer
55 views

Checking form input for an AJAX request

I've made a few functions to check form input for an AJAX request. I am still getting used to JavaScript and some of these AJAX requests. I am looking for any suggestions to better work with ...
3
votes
1answer
59 views

Improving fading functions

Regarding these two functions, which do the same thing... Large and confusing: ...
3
votes
2answers
110 views
2
votes
1answer
32 views

Reusing select statement

I am checking if there are any rows in a table with some conditions. If there are more than 1 row, it should filter again with some more conditions. ...
11
votes
2answers
266 views

Function wrapper like std::function that uses “small buffer” allocation

My Function class is similar to std::function with the small-buffer optimization. However, it always uses a small buffer and ...
3
votes
1answer
104 views

Web page based on a sample from a book

I've created a web page based on a sample from a book. It works fine, but seems to have become too complicated. ...
11
votes
2answers
119 views

Mapping enum to function - request / response library encapsulation

I'm writing code for an embedded device - specifically, a camera. The idea is different camera manufacturers can implement the code so it properly works with their camera. Here, I'm encapsulating the ...
3
votes
2answers
103 views

Returning nested array with added key=>value

This works, but do I have to make a new array, result, or is there a way to just insert the field I need into each $key of the ...
1
vote
1answer
99 views

Optimizing method and removing useless code

I have such function which is parsing beautiful soup elements: ...
4
votes
2answers
195 views

Updating necessary data using just one function

My objective is to update necessary data using one function instead of having different functions to update different fields. So, I've created one and I think this is not really elegant, efficient or ...
3
votes
0answers
24 views

Drawing and Painting a Menu Component

I have produced a working menu component for a project I'm working on, but would like to reduce the amount of code used and improve the methods - especially in the Paint implementation - still ...
3
votes
1answer
60 views

Taking data from staging table and inserting into target tables

I have the below mentioned function written in plpgsql which is working fine. I want someone to review it and let me know how can I improve its performance. This function takes data from staging ...
10
votes
2answers
88 views

Scalability of running commands from user input

Here is some code I have that has been extracted and shrunk down from a project of mine. ...
5
votes
1answer
71 views

Test if Excel is open without relying on catching an error

Getting a hook on an open instance of Excel is something I do all the time. I'm now questioning if I'm doing this the best way. I'm particularly concerned with the fact that I rely on the ...
5
votes
1answer
98 views

Soccer winning probabilies from ELO strength indicator

What can I do to improve this function, which calculates the win expectancy of a soccer team, given their strength: ...
3
votes
2answers
213 views

How to organize a paint cost calculator using functions?

This is the task I was given after completing my program. I don't have a clue what procedures and functions are to be honest. Therefore I have no clue on how to break down my program into different ...
1
vote
2answers
56 views

Series of repetitive content-loading functions

A friend helped me put the following code together. As can be seen, it's made up of a series of repetitive loadContent() functions. I've just shown the first two ...
2
votes
1answer
112 views

How can I optimize my insert function for the cuckoo hash table?

I'm working on class for a hash table where collisions are corrected using cuckoo hashing, I had difficulty writing the insert function, the function is supposed to insert the key if the ...
4
votes
1answer
766 views

jQuery animate opacity, fade, & slide up page load effect

This is the first time I've actually made my own jQuery script from scratch, because I couldn't find exactly what I was looking for. My code works how I want it to, although I don't know if I did it ...
0
votes
2answers
41 views

Default arguments for functions in Python [closed]

I was wondering what is the convention for return default types for python functions for e.g the below should Official return ...
10
votes
2answers
229 views

Hangman game with hard-coded word or phrase

I feel that this implementation can still be simplified. I've tried to keep variable scopes low and have used as much of the standard library as I could. It currently works with a hard-coded word or ...
3
votes
2answers
72 views

This snippet of scheme calculates a value in pascal's triangle

I'm working through SICP and have implemented exercise 1.11 (Pascal's Triangle). What I'm curious about here is performance considerations by defining functions within the main function. I would ...
1
vote
2answers
47 views

How can I optimize this string function so that it could work on very large strings?

I want to build a function which finds the longest substring that is common between two large strings, I want to do this using the first two functions. I'm running it on very large strings (containing ...
0
votes
1answer
45 views

Add user star function triggering PHPmailer email optimisation

The function below simple allows a logged in user to "star" another user for convenience when trying to find the that user another time. At the moment the function works as it should, it inserts the ...
0
votes
1answer
333 views

Preferred way to return to main menu [closed]

When we have function calling other functions for example a main menu calling a sub-menu and we want to exit the sub-menu and get back to the main menu (point of calling), do we use ...
2
votes
1answer
43 views
5
votes
2answers
265 views

Splitting a list by indexes

I am trying to build an efficient function for splitting a list of any size by any given number of indices. This method works and it took me a few hours to get it right (I hate how easy it is to get ...
4
votes
2answers
61 views

Page loader function

This is the function which I wrote and am currently using in my project. I want to know if there is a better way to write it: ...
11
votes
4answers
473 views

Similar methods using loops

Is it recommended to combine two similar methods into one? ...
10
votes
7answers
1k views

Project Euler #3 - largest prime factor

I was going through the Project Euler problem #3 and made a program to solve it. The problem is as follows: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of ...
6
votes
2answers
181 views

Pattern to avoid Variable Functions?

I have some PHP code where I use Variable functions to call the right function. I need to build a chart array (for example), and the chart array that comes out has a fixed format. But the data that ...
10
votes
1answer
329 views

When should I consider the number of my method arguments too big?

I'm writing a simple Pong game, I have a method bounce() that makes everything run: the ball, the paddles, score etc. and it uses 12 arguments: 3 counters, 2 ...
4
votes
2answers
452 views

How do I avoid duplicated code in these overloaded functions?

I have the following overloaded functions. All the code is the same as except for their format (%s v.s %lu), so I couldn't use ...
5
votes
1answer
60 views

Eliminating repetitiveness in code to test hash functions

I usually take my school code as a playground to mess around with things. I was given a bunch of premade hash functions and had to test their output and find when they reach a specific lower range. ...
1
vote
1answer
56 views

Optimising and consolidating multiple PHPMailer functions

So the two functions below both send emails via PHPMailer but both hold different messages (which use different data from the db). I was just wondering (as I plan to use PHPMailer more) a way to ...
1
vote
1answer
161 views

Test 2 time ranges to see if they overlap

I am doing a project for school and had to create a function to check if 2 time ranges overlap. I searched the net a bit but failed to find a simple function to do that. I played around a bit with my ...
4
votes
2answers
179 views

Implementation of atoi()

I implemented the atoi() function! Here is my code: ...
8
votes
1answer
471 views

PDO sign up function inserting data into multiple tables

This is a sign up function called on form submission. It firstly inserts key user data into the users table. If successful, secondary data is then inputted into ...
4
votes
1answer
139 views

Fix base64 data URI scripts function

So I noticed Chrome has quirky behaviour when it encounters script tags whose src is a base64 value. I decided to write a quick ...
3
votes
1answer
60 views

Using classes vs. using functions

I am trying to learn how to tell if my code will be better off creating a class as opposed to using many functions. I am a new Python programmer trying to get the hang of when classes should be ...
1
vote
1answer
326 views

Test whether or not a 4x4 matrix is a magic square

Here is what I have. I have it outputting most of the sums just so I can check there values. I think the problem is with the value of the elements in the array storing the column sums. I would greatly ...
0
votes
2answers
53 views

Trying to convert an extended Array.prototype to a function

I got a random image rotator working by using the following script (demo). But I was told that it is a bad practice to extend Array.prototype. And it does. It ...
7
votes
1answer
595 views

Command line reverse polish calculator

Write the program expr, which evaluates a reverse Polish expression from the command line, where each operator or operand is a separate argument. For ...
3
votes
3answers
328 views

Return value when the requested variable returns null

I have a method that returns a list from a HTML page: ...
6
votes
1answer
102 views

Functions that converts day of year to month and day and reverse with error checking

There is no error checking in day_of_year or month_day. remedy this defect. Here is the solution: ...
1
vote
1answer
43 views

Reducing multiple function calls [closed]

I can't quite figure out the best way to approach this. So I have a validation function that contains various other functions inside of it for validating email, phone and zip. This works fine but it ...