Most voted "function" questions
The function (also called procedure, method, subprogram, or routine) is a portion of code intended to perform a single, specific task.
Learn more…1,309 questions
Sort by count of
-
10
votes2
answers73
viewsOn the implementation of some() and Every()
I’m trying to understand how the implementation of some() and every(), but I did not understand very well the two implementation algorithms. some(): Array.prototype.mySome = function(callback,…
-
9
votes5
answers3697
viewsHow to import a variable within a function of a class?
I’d like to take the $valortotal and take it into a function of a class as can be seen in the example below. Thank you. $valortotal = 15.00; class CreatePaymentRequestLightbox { public static…
-
9
votes2
answers589
viewsIs it possible to name a parameter at the time of the function call?
Can I "access" a specific parameter of a Javasscript function, that is, give a value for a given parameter? As an example is better than text (since I don’t know how to explain myself properly),…
-
9
votes3
answers197
viewsWhat is the function of this 'and' that is passed as a parameter?
The example I’m going to show you here is just to illustrate. I’d like to really understand how this one works e which is usually passed as a parameter in various functions that matches in codes…
-
9
votes2
answers13617
viewsPython - 'int' Object is not iterable
Hi, I’m creating a character converter for your ascii code through a recursive Python function. However I have a problem "'int' Object is not iterable". This is my code: def cod(n): for i in n: i =…
-
9
votes1
answer325
viewsIn C++ where are the functions of the objects in memory?
In C++ when an object is declared, class variables are stored in the stack or in the heap depending on how the object was created. With the operator sizeof() it is possible to test and realize that…
-
9
votes4
answers199
viewsDifference between syntax to declare a function
Reading this answer, I realized different forms of call for a function using jQuery. The first way would be this: $('#dois').on("click", testar); function testar() { console.log('Teste Dois'); } And…
-
9
votes3
answers189
viewsLEN function, know number of characters of a number
In the example below the result of the query instead of returning 7 is returned 5. DECLARE @valor money = 10.6879 SELECT LEN(@Valor) The impression I get is that when the number is the type money ,…
-
9
votes2
answers1223
viewsWhy don’t you need the `&`in the `scanf();`?
I learned that the variable always has to have &, but in this example you don’t need and still show the result. Why you didn’t need the & in the scanf();? #include <stdio.h> int…
-
9
votes4
answers2878
viewsTwo "Return" in a function
How it works if there are two (+) return in a Python function? It would return the second value, or only the first? Example: def soma(a, b): x = a + b y = 'qualquer coisa' return x return y…
-
9
votes1
answer191
viewsWhat does the [&] operator mean before a function?
I’m trying to read the code of a function that’s defined like this: auto loop = [&](int ntensor, char** data, const int64_t* strides, int64_t n) { ... }; What does the [&] before function?…
-
9
votes1
answer144
viewsWhy Arrays and Functions are Objects?
I learned that objects store properties and methods: let objeto = { propriedade: "valor da propriedade", metodo: function() { return "retorno" } } But I see sites calling functions and arrays of…
-
9
votes1
answer74
viewsA function created within another function is created with each call or persisted by reference?
In the call for the declaration const minhaFuncao = fora(), i am storing the function execution result fora, that in this case would be the function dentro in minhaFuncao. In this case, am I…
-
8
votes3
answers20561
viewsHow to create functions in jQuery?
I would like to know the correct way, following good practices, to create functions in jQuery. I’ve used it like this: var focusToEnd = function() { ... } And also so: ; (function($) {…
-
8
votes2
answers389
views*apply with three-argument functions in R
I created a function of three arguments and I want to apply it to a Matrix 200 X 3 where in each line are the three arguments I need to use in the function. As a result I would get a vector of size…
-
8
votes3
answers2955
viewsFunction that returns function in Javascript
I started studying Javascript a short time ago and came across a situation in a code (exercise) that I can’t understand. function hi(a,b) { return a*b; } function hello(a,b) { return hi(a,b+1); }…
-
8
votes2
answers1094
viewsHow to declare a function within another function in C#?
In Delphi it is possible to declare function within the block of a given function, see this example done in Delphi: procedure TForm1.btnRunClick(Sender: TObject); begin mostrarNome('Carvalho'); end;…
-
8
votes2
answers271
views -
8
votes4
answers5555
viewsDetermine the nth Fibonacci term with recursion
I don’t understand anything about recursive functions, even debugging, is very confusing for me. Someone can explain me in an easy way? I tried to analyze the following code: #!/usr/bin/python def…
-
8
votes2
answers308
viewsWhy does Kotlin use a way of declaring functions and variables other than "traditional"?
Traditionally the return type and variable type are indicated at the beginning, before the name: public int soma(int a, int b){ return a + b; } In Kotlin he is named after: fun sum(a: Int, b: Int):…
function characteristic-language kotlin variable-declarationasked 7 years, 3 months ago ramaral 44,197 -
8
votes1
answer1237
viewsDoes the type annotation in a function not guarantee the type in Python 3?
It is known that in Python it is not necessary to define the type when declaring a variable and this is interesting, however, when creating a function, I cannot restrict the types of attributes, so…
-
8
votes2
answers144
viewsPrint the result of a for JS inside a <p>
I’m doing a college paper that consists of making a tabuada generator. It’s working perfectly when I use it console.log to show the result, but when I use .innerHTML = resultado to display in a tag…
-
8
votes1
answer140
viewsFunction to void pointer conversion*
Recently, I was trying to solve a problem in a program of mine in C and, by chance, I came across some answers from Stack Overflow in English which stated that converting a pointer to a function to…
-
8
votes2
answers105
viewsHow does an array of functions recognize the position of the next element?
Why do you ask: The question may seem strange, but is that I am a beginner in programming and at this moment I am studying pointers to function and in an example in the book by which study is…
-
8
votes2
answers146
viewsWhat is Function.prototype.call() for?
I get confused in using the method call(). It serves to call a function, inherit the parameters of a function or the properties? Another question of mine is in relation to the keyword this passed as…
-
7
votes2
answers1022
viewsHow to get the return of an instantiated Function (new + Return) - Javascript
I have a Function where I assign values in this, why it will be instantiated function Teste(){ this.valor='Valor no this'; return "Valor no return"; } I urge her var t = new Teste(); But now, like…
-
7
votes2
answers1844
viewsHow to declare an anonymous function in Python?
How do I declare and how an anonymous function of Python?
-
7
votes1
answer752
viewsWhat is the correct way to declare a javascript Function?
For some time now, I have been observing the use of two forms of function javascript, being the following: - Form 1: function soma1(val1, val2){ return val1 + val2; }; - Form 2: var soma2 =…
-
7
votes3
answers1181
viewsPassing vector to functions
How do I pass a vector to a function? Something that, on the Moon, would be like this: vector = {"V", "e", "t", "o", "r"} function getVector(vector, pos) return vector[pos] end…
-
7
votes1
answer341
viewsFunction Expression vs Function declaration
What is the definition for Function Expression and Function declaration? What are the main advantages of one in relation to the other?
-
7
votes1
answer401
viewsHow to create a function in the J language?
How to create a function in the J language? All the examples I found online show only how to describe functions through a Fork: media =: +/ % # media 1 2 3 4 2.5 The code above (+/ % #) is the same…
-
7
votes1
answer598
viewsIs it correct to return a memory address in function?
I was asked to design a function that was called, open a file. txt and return the pointer of this file, ie return a memory address. However as I know memory is only temporarily allocated for…
-
7
votes1
answer702
viewsUse a void function as a parameter of another
Let’s assume that I need one function to perform to a certain point, call another, do some action, call another function, do one more action and finish executing. Whereas the called functions…
-
7
votes1
answer2455
viewsWhat is the correct way to declare a main() function?
In some of the research I’ve done, I’ve noticed that there are some different ways to do it, like the examples below: int main() int main(void) void main() // entre outros... I know that statements…
-
7
votes2
answers330
viewsDynamic allocation and runtime of functions
When we use any of the dynamic allocation functions in C (malloc, calloc, realloc, etc.), within a function that is called by main, will the memory remain allocated at the end of the execution of…
-
7
votes1
answer3570
viewsWhat is the purpose of using inline functions in the C language?
I would like to know what is the purpose of functions inline in the language C? Is there any difference in performance or other characteristics that should be taken into account in comparison to…
-
7
votes2
answers1189
viewsWhat is an output parameter?
Consider the following example: appendFooter(s); Analyzing the function signature, we have the following: public void appendFooter(StringBuffer report) The parameter s is considered in the above…
function parameters language-independent computer-scienceasked 8 years, 1 month ago Filipe Moraes 8,737 -
7
votes1
answer304
viewsIs it correct, following object orientation, to use pointers to C++ functions?
I am creating classes that represent items in a menu, each item performs an action and I am assigning the action by a function pointer to each instantiated menu item, is this valid by following POO?…
-
7
votes2
answers1249
viewsReturning function string directly and with array
What works: void *teste(); int main () { printf("\nRESULTADO: %s\n", teste()); return 0; } void *teste(){ return "Ponteiro"; } What goes wrong: void *teste(); int main () { printf("\nRESULTADO:…
-
7
votes1
answer6487
viewsHow does a function run automatically without being called?
I can create a Javascript function and call it as follows: funcaoTeste = function() { console.log('Ola funcao teste'); }; funcaoTeste(); To perform the function I need to call her funcaoTeste(),…
-
7
votes1
answer144
viewsThe __fastcall, necessary or not?
What is the usefulness of using __fastcall in the C function call++?
-
7
votes2
answers2689
viewsRecursive Functions in Javascript
Could someone please clear me of a doubt ! function recursiveFatorial(x){ if (x == 0) return 1; else return x * recursiveFatorial(x-1); } console.log("Resultado da funcao recursiveFatorial:…
-
7
votes4
answers4137
viewsIs there a "main()" function in Python?
In some languages, as in C, we have the function main() which is usually the default entry point of the program. There is something similar in Python?
-
7
votes1
answer114
viewsIs every anonymous function a closure?
Every anonymous function is considered a closure or only those that refer to the context where they were created are? I wish I knew that to distinguish them correctly. I know the concepts and the…
-
6
votes2
answers446
viewsFunction using as arguments successive values of a column (R)
I have a data.frame with 13 columns and 78 rows. I need to do it for each column ((x1/x2)^12)-1, being x1 the value in the first row of the first column, x2 the value contained in the second row of…
-
6
votes1
answer1320
viewsrbind error: "Error in match.Names(clabs, Names(xi))"
I’m trying to build a function that counts the number of complete cases in files. csv (data frames), ie the number of lines with values (and not "NA"). The function I wrote can read the file(s)…
-
6
votes2
answers1558
viewsCheck if a parameter has been provided for the function
Assuming a Javascript function with parameters: function minhaFuncao (param1, param2, param3) { // fazer algo ... } And then using it as follows: var param1 = "bubu"; minhaVariavel = minhaFuncao…
-
6
votes4
answers1247
viewsFunction within another
In Javascript, I can structure my code well by placing auxiliary functions inside other functions. For example: I get something similar in C#? If not, how do you not leave the auxiliary functions…
-
6
votes3
answers4229
viewsCheck the running time of a Javascript function
I wonder if it is possible to know the running time of a certain javascript function.. This function does not need to bring external data, it can only handle form tags, set value, calculate fields,…
-
6
votes2
answers213
viewsDifference between ":" and "." in the methods of a Lua table
I came across two different statements that left me confused. obj = {} function obj.Create(name) end function obj:GoGoGo(name) end What is the difference between the declared function and the .…