FAQ Database Discussion Community


Array of constant pointers to functions

c,function,pointers,constants,ansi
I want to make an array of constant pointers to functions. Something like this: #include <stdio.h> #include <stdlib.h> int f( int x); int g( int x ); const int ( *pf[ ] )( int x ) = { f, g }; int main(void) { int i, x = 4, nf...

JavaScript recursive function breaks when () included in call

javascript,jquery,function
I have created a countdown "Pomodoro" timer using JavaScript and JQuery. The code snippet I am referring to is the following: var time = 1500; var cycle = "long"; var tracker = 0; var paused = false; //Timer countdown function function countdown(){ if (!paused) { var seconds = ("00" +...

function pointer is not a function or function pointer

c++,function,pointers
I have following problem: void MyClass::LoopFunction(vector<Item>& items,void (MyClass::*funcy)(vector<Item>&,int)) { for(SInt32 i = 0; i < 50; i++) { funcy(items,i); } } It says: Called object type 'void(MyClass::*)(vector<Item>&,int)' is not a function or function pointer Can anyone help me to find a solution for this?...

What makes the object.prototype to the constructor function if he has no name? [duplicate]

javascript,function,class,inheritance,prototype
This question already has an answer here: Defining a Javascript prototype 5 answers My following code is this: var triangle = {a:1, b:2, c:3}; function constructorFunction() { this.color = "red"; } constructorFunction.prototype = triangle; I know that the prototype keyword extends classes in this syntax: Object.prototype.method = function() {}...

C# add to list not working

c#,function
I am new to C# and I am just trying to create a simple program to perform some basic calculations on VS2010. The problem I'm having is that I don't seem to be able to add the calculated value to a list. List<double> distance = new List<double>(); List<double> speed =...

Update input number variable onclick

javascript,jquery,html,function
I am trying to create a calculator style thing, where you put in how many years into a input, you hit submit and it gives you different results below without reloading the page. I have all the calculations working right now, but I just cant get the input number variable...

How to perform a statement inside a query to check existence of a file that has the query id as name with less resources in laravel

php,function,laravel,laravel-4,eloquent
i'm looking for away to see if the query 'id' has a folder with the same id as name in the file system, i did it but it will slow down the drive in the future with lots of files $query = Model::all(); if(Input::get('field') == 'true'){ $filenames = scandir('img/folders'); $query->whereIn('id',...

PHP: How to use function to either echo result or to save it in a variable (partially working)

php,function,variables,echo
I am new to PHP and hope someone can help me with this. I have the following function to which I can pass an itemID (unique integer) which it will then use to return the corresponding translation from a previously created array (this is just the final part). PHP function...

what does php's header function do?

php,function,http,header,content-type
I can't find any solutions to this problem. I'm having hard time with this code. Based on what I searched: HTTP/1.1 200 OK - means that the page is good or OK. I don't understand this header function parts only. It is actually part of code. My questions are: Why...

jQuery - Value in Function

jquery,arrays,function
My array: array.name = "Thiago"; array.date = "01/01/1990"; I want a function like this: function myFunc( array, fieldToCompare, valueToCompare ) { if( array.fieldToCompare == "Thiago" ) alert(true); } myFunc( myArray, name, "Thiago" ); is it possible?...

JS Browser with pause function, help please

javascript,function,browser
I wrote this program in js that goes through a list of URLs, where it stays on each page for a few seconds, closes the current window, and open the next in line. Everything works perfect, now I need it to stop/pause every 5 links. The second part of this...

How do I return a value from a second function in PHP?

php,function,return,value
I'm a green green newbie trying to write a simple program in PHP. I use an HTML form to ask a "diner" to select an entree, which sends the choice to a PHP program.The PHP program is supposed to echo the entree choice, suggest a drink to the diner, and...

Fetch a function definition without rights on source files

php,function,source,server-side,definition
Premise A question between a friend of mine and me turned into this question: while in Javascript you can easily output a function definition, I argued it was nigh impossible in PHP if you have no access to the files where the definition is located. So, we decided to ask...

How do I set up a bash alias for a common working folder?

bash,function,alias
I want to set up a bash alias or function (let's call it "myfolder") to a common working directory (let's call it ~/some/deep/working/folder) and I want to be able to call it like this: cd myfolder/bob to access the child folder "bob". If I use alias myfolder='~/some/deep/working/folder', I can use...

How can I simulate a nested function without lambda expressions in C++11?

c++,function,c++11,lambda,allegro
I have the following code: int main(int argc, char **argv) { App app(800, 600); app.add_event_scene(Scene("Event Plot", event_plot)); Image x("sample.png"); struct foo { static void visual_plot() { x.draw(); } }; // Error. app.add_visual_scene(Scene("Visual Plot", foo::visual_plot)); app.run(); return 0; } And I get the following error: ||=== Build: Debug in Joy-Plus-Plus (compiler:...

How to return an array with unhappy numbers removed?

matlab,function
I'm quite new to using MATLAB, and am still trying to understand how to make this particular function. I understand the formula for performing this on paper, but I'm having trouble translating it into the required MATLAB syntax. How would a function be written such that it takes an array...

Error when using reduce() in Swift 2.0

function,swift,reduce,swift2
When I attempt to use the reduce function, I get an error saying: reduce is unavailable: call the 'reduce()' method on the sequence I already figured out how to do this with the enumerate() function but I cannot seem to solve this issue. Here is the line of code returning...

in jquery can i add a readonly attribute to a input that the only property i can touch is a function?

jquery,function,readonly
I have multiple inputs like that (unknow number) <INPUT id="ctl00_ContentPlaceHolder_txtSOPurchaserSapID" onkeydown="return scriptReadonly();" style="WIDTH: 150px" name=ctl00$ContentPlaceHolder$txtSOPurchaserSapID> there are not on the same page of the app, the id's and the names are dynamically loaded i cannot add a class because there are so many and i don't know the location of...

JSLint won't recognize getElementById

javascript,function,getelementbyid,jslint
JSLint gives errors with simple function, running on brackets with JSLint. Javascript: function soundSorry() { getElementById("player").play(); } Error codes: 2 Missing 'use strict' statement. getElementById("player").play(); 2 'getElementById' was used before it was defined. getElementById("player").play(); Any ideas?...

Read blank as missing(NA) in R data table

r,function,data.table
I am trying to create a function which can find missing location and impute the missing in a data table. Now this function uses is.na() extensively to find out the missing location and also to replace it with imputation value. It is working fine for all type of variable until...

Find out the biggest odd number from three arguments in a function [Python]

python,function
I need to write a function that will print biggest odd number from three input arguments. Here is my code. def oddn(x,y,z): odd_number_keeper = [] for item in x,y,z: global odd_number_keeper if item % 2==1: odd_number_keeper = [item] return max(odd_number_keeper) else: print 'No odd number is found' My codes seem...

Void function (c++)

c++,function,void,equation,quadratic
I want to create a program that solve quadratic equation (Ax²+Bx+C=0) using 2 void functions: one to insert the values of A,B,C, and the second for solving the equation. This is what I did: #include <iostream> #include <math.h> using namespace std; void add_nmbr(int a, int b, int c){ int *pa,*pb,*pc;...

Functions with pointer arguments in C++

c++,function,pointers,constructor,ampersand
I'm having some difficulties in understanding some aspects of functions with pointers. Here is the code I'm running: #include <iostream> using namespace std; class Item { public: Item(Item * it) { data = it->data; } Item(int d) { data = d; } void printData() { cout << data << endl;...

Interpret formulae/operators as functions

r,function,variable-assignment,formula,evaluation
Is it possible in R to assign custom functions to mathematical operators (eg. *, +) or interpret the formulae supplied with as.formula() as a directive to evaluate? Specifically, I would like * to be interpretted as intersect(), and + as c(), so R would evaluate the expression (a * (b...

Waiting without Sleeping? (C#)

c#,function,wait
So what I'm trying to do is start a function, then change a bool to false, wait a second and turn it to true again. However I'd like to do it without the function having to wait, how do I do this? EDIT Sadly I Can only use Visual C#...

Global scope for array of structs inside function - Swift

arrays,function,swift,struct,shuffle
I would like to shuffle my array questions and use the shuffled array in the program when it starts. I have created this function that shuffles the array. func shuffleQuestions() { var shuffledQuestions = shuffle(questions) } This gives me an array with questions shuffled that inherits the values from the...

Get array output of one function in another function php

php,function,codeigniter
I have below controller function of codeigniter, public function add_attachments($openid) { $config = array( 'upload_path' => './uploads/attachments/', 'allowed_types' => 'gif|jpg|png|jpeg|doc|pdf', 'max_size' => '1024000000', 'multi' => 'all' ); $this->load->library('upload', $config); if ( ! $this->upload->do_upload()) { $error = array('error' => $this->upload->display_errors()); } else { $data = $this->upload->data(); } $new_array = array_column ($data,...

How to have multiple variable function work with vectors

function,vector,scilab
I'm having trouble dealing with scilab functions ; I have an output in the form of a 1x6 vector, and I'd like to have a simple way to make it work with a 6 variable function. v = [1,2,3,4,5,6] ; function z=f(a,b,c,d,e,f) ... endfunction f(v) //returns error Thank you ...

Reversing the output of a function in python that is not a list

python,function,reversing
I will get a number for the output of this piece of code: base = int(raw_input("Pick your base: ")) base = str(base) question = "Pick your number! (the base is "+base+" ): " number = int(raw_input(question)) def func(number): if number != 0: sec = number/int(base) third = number - (sec...

Decremented value called in the recursion in Haskell

string,function,haskell,recursion,parameters
So, I have this function that aligns the text to the left for a given column width. I have already fixed some of its problems, but I am unable to make it not use the decremented parameter once it is called, but to return to the starting value of n....

How can I minimize this function in R?

r,function,optimization,mathematical-optimization
I'm attempting to write a formula that will determine a value of a that minimizes the function output myfun (i.e. a-fptotal). MWE: c <- as.matrix(c(.25,.5,.25)) d <- as.matrix(c(10000,12500,15000)) e <- 700 f <- 1.1 tr <- .30 myfun <- function(a) { b <- max(a-e,0) df <- data.frame(u1=c(c*b*.40),u2=c(c*b*.60)) df$year <- 1:nrow(df)...

How to condense this into a single function?

javascript,jquery,function,dry
I am really new to JS/JQuery, I cant figure out how to keep this code D.R.Y, if its even possible at all I don't know. I am using JQuery for an on hover effect with an image. Box1 being the div and the img_hover_effect being the overlay on hover. JS:...

SQL average age comparison function returns null

mysql,sql,function,datetime
So, I'm working in MySQL, writing a function that averages the ages of women and men from a table and compares them, and returns which is greater. Dates are in the format of YYYY-MM-DD, and I'm using DATEDIFF(). The function appears to work correctly, but when I run the script,...

Can't understand this Javascript function (function overloading)

javascript,function,methods,overloading
I'm reading Secrets of Javascript Ninja and came across an example that I cannot fully understand. This same example was cited by some other user here before, but their doubts are different than mine. Here is the example: function addMethod(object, name, fn) { var old = object[name]; object[name] = function(){...

is return main(); a valid syntax?

c,function,return,language-lawyer,return-type
I found some interesting code lines: #include <stdio.h> int main() { printf("Hi there"); return main(); } It compiles ok (VS2013) and ends up in stackoverflow error because of the recursive call to main(). I didn't know that the return statement accepts any parameter that can be evaluated to the expected...

Stuck on Structs(c++)

c++,function,struct
Okay so this is what Ive been asked to do "make a struct called Coordinate that contains the latitude and longitude of a point on the surface of the Earth. The struct should also store a label or name for the coordinate (e.g., “Calgary”). Both the latitude and longitude member...

Infix operator with missing argument

function,haskell,infix-notation
Is it possible with Haskell to have an operator (infix function) working with a missing argument ? (rather like - meaning a subtraction or a negative sign) For example, I have this operator : data1 <*> data2 Is it possible to make it work with a default value if first...

Python avoid item = None in a request of multiple items

python,function,request,urllib,nonetype
I'm doing a loop for multiple requests on a web database, each time it takes one geneId to request it to the database. If the geneId is referenced I can use the data I get for another request on a second database. But if the geneId is not referenced, it...

sum of Digits through Recursion

java,function,recursion,sum,digit
I am trying to make a recursive function which should return the sum of digits. The function should have only one argument. So far I have this; public int sumDigits(int n) { if(n%10 == n) // last digit remains return n; else{ int rightdigit; rightdigit = n%10; // taking out...

Counting bytes received by posix read()

c,function,serial-port,posix
I get confused with one line of code: temp_uart_count = read(VCOM, temp_uart_data, 4096); I found more about read function at http://linux.die.net/man/3/read, but if everything is okay it returns 0, so how we can get num of bytes received from that? temp_uart_count is used to count how much bytes we received...

set time interval for javascript function in “microseconds”

javascript,jquery,function
I wish to animate an element in such a way that it move only 1px downwards every 1 microsecond, that is 0.001 milliseconds. var microsec = 0.001 $("div").animate({top: "+=1px"},microsec); Please advice....

Generic method to perform a map-reduce operation. (Java-8)

java,function,generics,java-8,overloading
How to overload a Function with generic parameter in Java 8? public class Test<T> { List<T> list = new ArrayList<>(); public int sum(Function<T, Integer> function) { return list.stream().map(function).reduce(Integer::sum).get(); } public double sum(Function<T, Double> function) { return list.stream().map(function).reduce(Double::sum).get(); } } Error: java: name clash: sum(java.util.function.Function<T,java.lang.Double>) and sum(java.util.function.Function<T,java.lang.Integer>) have the same erasure...

session value in javascript cannot be set

javascript,function,session
I am quite new to javascript, I wonder why my session value in javascript wont be set to 1 even I tried. When call this function again, the value of the session will change again. My javascript code as below. <script type="text/javascript"> function Confirm() { alert(<%=Session["Once"]%> != 1); var value...

My is_prime function fails on 9, and I don't know why?

python,function
I have a bit of a problem. I am writing an is_prime function on, but whenever I run it, it fails on is_prime(9), and I cannot see why: def is_prime(x): if x < 2: ##because negative numbers, 0 and 1 are not prime## return False elif x == 2: return...

When are variables evaluated when passing them into functions?

javascript,function,variables,arguments
This is probably a simple question, but I would really like to know the answer. Are the arguments passed into a function calculated once and set as local variables or are they calculated every time they're used inside the function? For example: When you write a forLoop, you should set...

C++ need help figuring out word count in function. (Ex. Hello World = 2)

c++,function
I'm figuring out the algorithm on this function and it keeps crashing at runtime, here's the code snippet: int wordCounter(char usStr[]) { int index= 0, punct= 0; while(usStr[index]!= '\0') //If it's not the end of the sentence if(usStr[index]== ' ') //If it finds a space index++; while(usStr[index]== '\0') //If it's...

Passing Pointers through a Function Then Getting Giberish

c++,function,pointers
I've got the following code, and it seems to be printing gibberish. However, when I change the size of the array from "r" to 5000, it works perfectly. Can anyone explain this behavior and show me how to fix it? I've done a lot of research on this, but can't...

Casting a String Into a Function in R

r,function,casting
I have a Shiny app in R where I want users to be able to create functions on the fly by entering text in a text box. To enable this functionality, I would like to know the following: How would I go about casting a string object containing a function...

How to produce legend in ggplot by mapping aes_string from different data frames in ggplot?

r,function,ggplot2
I am trying to create a legend for ggplot density that compares one group to all groups. Using this example - R: Custom Legend for Multiple Layer ggplot - I can do this successfully with code below. met1 <- data.frame( Score = sample(1:10), Group = sample(c("Group1", "Group2", "Group3"), 30, replace...

How to execute JavaScript function in an Ajax() Response

javascript,jquery,ajax,function,eval
I have a home page that load the ajax() response and post it to UL as LI content, with the same page I have script function that can select the LI content with trigger for another function, but isn’t working. PAGE 1 HTML <ul id="feature-deals" class="list-products allShopping-deals"> </ul> SCRIPT $(document).ready(function(){...

PercentOfSum(fld, condfld) SSRS Equivalent

function,reporting-services,crystal-reports,ssrs-2008,ssrs-2008-r2
Crystal Reports has a built-in function PercentOfSum(fld, condfld) (documentation here). How can I achieve the same functionality in SSRS?

How to allow variable parameters passed to function

c,function,parameter-passing
I have a function that accepts 3 parameters, however I also want it to only accept the first two and not care about the third. How can I do this in C. I tried just declaring the function in the header file as void list() thinking this might imply that...

Excel Function Error

excel,function,text
I am trying to create a cell from a Excel to show three values depending of a number from another cell. The function I use is =IF(H4<100;(TEXT(Probabil));(IF(H4<50;(TEXT(Sigur));(TEXT(Da)))) NOTE: The function outputs are in Romanian. Probabil means possible, Sigur means sure and Da means yes. I tried to use " before...

Swift func - Does not conform to protocol “Boolean Type”

function,swift,dictionary
Yes it's man vs compiler time and the compiler winning yet again! In the func getRecordNumber I am returning a Bool and a Dictionary func getRecordNumber(recordNumber: Int32) -> (isGot: Bool, dictLocations: Dictionary <String, Double>) ... return (isGot, dictLocations) However after I have called the func and question the Boolean isGot...

Can anyone improve on the below Fuzzyfind function for VBA?

algorithm,vba,function,find,fuzzy-search
This function lets you find similar strings from a range without having to do an exact search. The formula looks like this: =FuzzyFind(A1,B$1:B$20) assuming the string you are performing a search for is in A1 and your reference or options table is B1:B20 The code is here: Function FuzzyFind(lookup_value As...

Functions and pointers in C

c,function,pointers
I am trying to assign the return value of a function to variable, the problem is that this return value is an array, I understand that it will return a pointer, but as you can see below I just couldn't do the proper assignment, I've looked at many questions and...

How to have parameters to a button command in tkinter python3 [duplicate]

python,function,python-3.x,tkinter
This question already has an answer here: Python Tkinter: Passing arguments to Button widget 1 answer commands in tkinter when to use lambda and callbacks 2 answers I want to have UI where when I press a button, stuff pops up in the console. The issue is the stuff...

Why is the button.setText() shows error

java,android,function
I made a function that is called every 1 second and within that function I wrote myButton.setText("Stop"); now everything works great without that code,but whenever I write this code,the mobile I make my test on shows message "app has stopped working" I've been looking for a solution 3 days now,help...

Count neighboring cells

java,function,for-loop
I don't understand what is wrong with this loop, it normaly would check the surrounding cells of (x,y). When calling this function, there is only 4 passages in the loop and not 8 This is probably a stupid mistake but I cant see it ! private int countAliveNeighbors(int x, int...

Function Returning Square Brackets When Using Array Methods

javascript,arrays,function
I've just started an exercise in Chapter 4 of a book called Eloquent JavaScript. The exercise asks me to do the following: "Write a range function that takes two arguments, start and end, and returns an array containing all the numbers from start up to (and including) end." However, when...

Why can we use undefined object in Javascript function declaration?

javascript,function
Chromium WebUI has a cr.js file, which offers cr.define( name, fun ) method, for modulization. All the porperties of the object that fun returns, will be added to the name namescope object. In chromium browser bookmarks manager page(chrome://bookmarks), a Javascript source file named bmm.js is loaded. This is a Javascript...

How do I fix function compilation error?

oracle,function,plsql,sql-update
--this is my function create or replace function sal_incr ( p_grade number) return number is v_inc number; begin select raise_percent into v_inc from sal_inc where grade_id in (select grade_id from emp_task where grade_id = p_grade); return v_inc; end; -- Update statement update emp_task set sal = sal + sal_incr(grade_id); --...

When calling a recursive function to order values, it misses one. How do I fix this?

python,algorithm,function,recursion
I have a recursive function that reads a list of scout records from a file, and adds then in order of their ID's to a list box. The function is called with addScouts(1) The function is below: def addScouts(self,I): i = I with open(fileName,"r") as f: lines = f.readlines() for...

R function that calculate correlation between two elements of a data frame if condition is meet

function,r
So I've been trying to make this function work for days.. function behaviour should be as follows: go throw a number of specified csv's = id read.csv's and rbind them all in one dataframe remove all rows that have na values and keep only complete ones. condition 1 Then if...

strip_tags() on MySQLi Query and PHP Function [closed]

php,mysql,string,function,mysqli
I'm trying hard to learn how to create functions, and I don't know what I'm doing wrong here. Could someone explain it to me please? I'm not using strip_tags(), why it's getting me this error? I don't need it to return, I just to need to update database if $xp...

Passing a vector as argument to function

c++,function,stl
I have a function like this: void Foo(std::vector<bool> Visited, int actual element); I actually use this function for a BFS in a Graph, but it goes in an infinite loop. I suspect it always creates a copy of the Visited vector. How do I make it change the vector, which...

Why doesn't this swift function work?

string,function,swift
This function takes two string arguments. It is supposed to return the first one as dashes except where the character is somewhere inside of the second argument. Example: dashes_except("hello", except: "lo") -> --llo The function works fine when the except argument is only one letter but fails when it is...

Scope in javascript acting weird

javascript,function,scope,pass-by-reference
Object are passed with their reference in javascript. Meaning change in that object from any where should be reflected. In this case, the expected output was {} for console.log(a) function change(a,b) { a.x = 'added'; a = b;//assigning a as {} to b } a={} b={} change(a,b); console.log(a); //expected {}...

Once again: JS functions and objects

javascript,function,object
So I am reading up on JS with Programming JS applications and JS the goodparts. Reading through objects and functions.. which are apparently the same. According to Crockford himself (and practically everybody). But then I ask: if they are the same then why if I have an object: var myObject...

MySQL function with parameters syntax error

mysql,regex,function
I'm trying to convert this query to a MySQL function SET @v1 := ( SELECT count(id) as count FROM article_category where (title like "About Usd") or (title like "About Usd-%" and title regexp '[0-9]$') ); INSERT INTO `article_category` (`title`,`meta_data`,`meta_description`) VALUES ( IF(@v1 <= 0, "About Usd", CONCAT("About Usd","-",@v1) ), "ddddD",...

XQuery - Doing math on elements within a sequence and aggregating results

function,operators,xquery,sequence,aggregation
I'm trying to execute a XQuery sum function in a multiplication of two XML elements, but it has been difficult to avoid the iteration in a sequence of elements. For example, consider this case: sample data: <Orders> <Order> <OrderKey>1</OrderKey> <LineItem> <LineNumber>1</LineNumber> <Quantity>41</Quantity> <ExtendedPrice>70848.0000</ExtendedPrice> <Discount>0.0913</Discount> <Tax>0.0663</Tax> <ReturnFlag>A</ReturnFlag>...

Object Oriented Python - rectangle using classes and functions

python,function,class,oop,methods
I am creating a program in Python that will utilize object oriented programming to print the properties of a given rectangle. The project has these given constraints: The purpose of this lab is to give you practice creating your own object. You will be given a main function that expects...

need help to search element from vector of struct

c++,function,c++11,std
I have vector of struct partationPartItemTag_t type typedef struct partationPartItemTag { std::string partition; std::string partGroupId; std::string mathTuid; std::string partNumber; tag_t itemTag; }partationPartItemTag_t; I want to find element from vector having value for partition == 'a' and partGroupId == 'b' I have written following code and its working fine with C++11...

Toggle text + also call method with argument?

jquery,function,toggle
Im trying to toggle change a text on spacebar press with jquery ( works ) but also try to call a method with custom argument. How would below code example needs to me modified to do this? I have tried all kinds of ways but don't understand how to add...

xslt condition output one by one

xml,function,xslt,if-statement,xpath
hope that someone has a suggestion about this: I need to have in each 'a', all the 'b' that have @n equal or bigger than the @n of the 'a' in which they are. I am using xslt 2.0 and Saxon-HE 9.6.0.5 XML source: <blabla> <a n="2"></a> <a n="6"></a> <b...

My function will log a value to the console, but it won't return the same value - why? [duplicate]

javascript,arrays,function,recursion
This question already has an answer here: Return value of recursive function is 'undefined' 1 answer I've created the following function to flatten a nested array: function steamroller(arr) { arr = arr.reduce(function(a, b, i){ return a.concat(b); },[]); if (!Array.isArray(arr[arr.length-1])) {console.log(arr); return arr;} steamroller(arr); } steamroller([1, [2], [3, [[4]]]]); The...

How does ((a++,b)) work? [duplicate]

c,function,recursion,comma
This question already has an answer here: What does the comma operator `,` do in C? 8 answers In the below block of code, I am trying to understand how the line return reverse((i++, i)) is working. #include <stdio.h> void reverse(int i); int main() { reverse(1); } void reverse(int...

A function to calculate cumulative maximum for a double matrix in MATLAB

matlab,function,matrix,max
Is there any function that can calculate cumulative maximum for a double matrix? I have a 1*3000 matrix and I need to calculate the cumulative maximum. For example if the matrix is: A = [8 3 6 7 9 10 6 2 2 3] The cumulative maximum array will be:...

JS: Is it possible “something(arg)” and “something.my_method(arg)” at same time

javascript,function,oop,methods
I know how create just a function something(arg) something = function(arg) { console.log('Function result', arg); } I know how create an object with function something.my_method(arg) something = { my_method: function(arg) { console.log('Method result', arg); } } Is it possible to write code, wher both something(arg) and something.my_method(arg) are exists? Like...

Call known function (with parameters) in class whose name is defined by string variable

java,function,class,variables
I have a bunch of classes of various names and each has a performLogic function that accepts a number of preset parameters (always the same): public final class DoSomeAction extends SetupAction { public void performLogic(param1, param2... I want a way where I can call it like this: String actionName =...

accessing a variable from outside a function and returning the variable. In a module pattern

javascript,function,module,scope
I'm learning about how to split up different functionalities into different section so I could have loose coupling. i have two object 1.'addition' and 2. 'subtraction'. I don't think that info matters for this Q. what i want to do is that when amount = 3 in the index.html file...

How to call a data.frame inside an R Function by name

r,function,data.frame,call
I want to write a function that runs the same analysis on different data.frames. Here is a simple version of my code: set1 <- data.frame(x=c(1,2,4,6,2), y=c(4,6,3,56,4)) set2 <- data.frame(x=c(3,2,3,8,2), y=c(2,6,3,6,3)) mydata <- c("set1", "set2") for (dataCount in 1:length(data)) { lm(x~y, data=mydata) } How do I call a data.frame by name...

Calling function and passing arguments multiple times

python,function,loops
I want to call the function multiple time and use it's returned argument everytime when it's called. For example: def myfunction(first, second, third): return (first+1,second+1,third+1) 1st call: myfunction(1,2,3) 2nd call is going to be pass returned variables: myfunction(2,3,4) and loop it until defined times. How can I do such loop?...

Stopping condition on a recursive function - Haskell

string,function,haskell,if-statement,recursion
So, I have this function which aims to align the text on the left without cutting words(only white spaces). However my problem is that I cannot find a stopping condition of the function and it goes infinitely. f n "" = "" --weak condition f n s = if n...

How to pass pointer to struct to a function?

c,function,pointers,struct
I am instantiating the struct within the main() function and I am passing a pointer to this structure over to a function. I would like to then pass this pointer to the original struct to another function, how would I do this? I am now lost in pointerception. struct coords...

sql server function does not allow return statement

sql-server,function,return
I am trying to create a function in sql server but it keeps telling me : A RETURN statement with a return value cannot be used in this context. I have many other functions and they all end with return @variable. So I must be doing something wrong here and...

Pick subset of functions as string & evaluate

javascript,jquery,arrays,string,function
I have a set of defined JS functions. I want users to pick a subset of these using a comma separated string. Then I want to randomly pick from their subset, and evaluate the function selected. I have this 99% working, except it is not evaluating for some reason. Why...

Return type of list front (C++)

c++,function,reference,linked-list,return-type
So I want to use a list for a part of my program. I'm trying to get acquainted to the library list, so I wrote a quick little program to help myself understand what's going on. It all works properly, but there's one thing I don't understand. According to this:...

ordering non-decreasing functions then adding them in R

r,function,order,sequence,rstudio
Need help with basic R function: Firstly order non-decreasing sequence from 4 different sequences and then order those 4 sequences into one. Im totally green in programing so please make it the simplest way possible. Edit1: puting some input data as required A={3,2,1,2} B={6,7,5,8} C={12,11,9,10} D={65,43,76,13} I would like it...

Selecting and removing a html select option without selecting by index or ID, using vanilla JavaScript

javascript,function,select,options
I need to remove an option on a select box, and I've figured out a potential solution in the code below, but it doesn't feel particularly 'safe' (if another developer decided to add an option to the backend, the option will re-appear). Is there a better way of achieving this...

defining functions with optional arguments

python,function,optional,def
Hi I'm trying to understand how to implement optional arguments in a python function. For example, in the basic function below def Ham(p,*q): if q: print p+q else: print p Ham(2) Ham(2,3) I expect Ham(2) to return '2' which it does, however Ham(2,3) gives an error. EDIT: Many thanks. Many...

Trying to include an array using a function to require the files with the array

php,arrays,function
I'd like to require files in my index.php file and use the array set in those files. The tree structure from where to get the files is: root/lang/nl/dashboard/default.php root/lang/nl/dashboard/users.php The code for those files is default.php // Default DASHBOARD language list if (empty($lang) || !is_array($lang)){ $lang = []; } $lang...

Is it possible to use $(this) in a function called from another function?

jquery,function,this
Sorry for the question title, I know it's not very well worded, but I couldn't really explain what I'm asking in a summary. I have a JQuery function tied to the click event of an element. For reasons that may well be flawed (other than making more sense to me...

Genetic Algorithm - convergence

java,algorithm,function,genetic-programming,convergence
I have a few questions about my genetic algorithm and GAs overall. I have created a GA that when given points to a curve it tries to figure out what function produced this curve. An example is the following Points {{-2, 4},{-1, 1},{0, 0},{1, 1},{2, 4}} Function x^2 Sometimes I...

passing arguments via reference and pointer C++

c++,function,pointers,reference
I am looking at a code snippet and I have this sequence. class MyVariable { .... CustomType z; .... } A.cpp calling a function f ( & myVariable) In an included file I do have this : B.h void f ( MyVariable * myVariable); B.cpp f( MyVariable * myVariable){ CustomType...

Delete file after “x” second after creation

vb.net,function
I want to delete file after 15 second of create that file. I use this code but no success. Private Sub Form1_Click(sender As Object, e As EventArgs) Handles Me.Click Dim test = Application.StartupPath & "\" + tte4 Timer1.Enabled = True If Timer1.Interval = 0 Then My.Computer.FileSystem.DeleteFile(test) End If End Sub...

How to skip a function

function,python-2.7
I am learning python and trying to make a little game. So my question is can you define a function but skip it and use it later. EX. def func() print"1,2,3,4" func() def func2() print "counting" func() func2() How would I skip func but still be able to print it...

call function after “loop” function for multiple elements is finished in jQuery

jquery,function,loops,animation
I've searched this site for a solution but couldn't find something to extract for my purpose. I have two functions. The first function fades in multiple elements in delay to each other until every element is faded in. Now I want to start the second function after the first is...

Replace paragraph in HTML with new paragraph using Javascript

javascript,function,onload,getelementbyid,appendchild
I am attempting to replace a p in my HTML doc with a paragraph created in Javascript. Once the page loads, two will be replaced with t. var two = document.getElementById("two"); document.onload = function myFunction() { var p = document.createElement("p"); var t = document.createTextNode("I am the superior text"); p.appendChild(t); document.getElementById("p");...

Python 3 random.randint() only returning 1's and 2's

function,python-3.x,random,dice
I thought I'd finally worked out all the kinks in the dice rolling code I wrote for practice, but then apparently I forgot to save my work last night, and when I rewrote it this afternoon, the random.randint function didn't seem to be returning any numbers other than 1's and...