Questions tagged [function]

33959 questions
1

votes
1

answer
503

Views

Function from other file is not defined

I wrap by $(function) both files for running code when page is ready. But for some reasons calling function from first file in second file gives me error 'ReferenceError: test is not defined'. First file: $(function() { function test() { alert(1); } }); Second file: $(function() { test(); });
DIAMONDMAN
-1

votes
0

answer
28

Views

How do I disable a function with another function in javascript, and vice versa? [on hold]

I want a function to be able to disable another function and to enable back a function. function myMove() { var id = setInterval(frame, 1); function frame() { if (pos == slutpos) { clearInterval(id); slutpos+=100; } else { pos++; karusellEl.style.marginLeft = pos + 'px'; } } if(pos>200) { //...
Krøsh
0

votes
2

answer
19

Views

Accessing rightBarButton function from another ViewController in Swift

I'm trying to access the rightBarButton function for showing cart from an another ViewController, although I can call that function but it won't display any image i.e cart image Below code show how am i calling this function. override func viewDidLoad() { super.viewDidLoad() // Adding Right Bar Butt...
ExecutionerAxe
1

votes
1

answer
3.7k

Views

Function implementation is missing or not immediately following the declaration, TypeScript class

I got a handwritten array to fill a table in my class, now I'm getting this array's content from a JSON on ngOnInit but it's not structured as I need. So I'm trying to write a function to fill the table array with this new one I'm getting on ngOnInit. The issue is that when I write code outside of...
prevox
1

votes
1

answer
154

Views

Function calling at the left side of the expression

Can we have a function calling at the left side of the expression? This code snippet works well but how? How can a function calling can be at left side and please elaborate how this snippet is executing and working well and what if i wouldn't have used static int in function definition.Thanks in adv...
Shivanshu
1

votes
1

answer
2.1k

Views

Pandas DataFrame as an Argument to a Function - Python

Suppose a Pandas DataFrame is passed to a function as an argument. Then, does Python implicitly copy that DataFrame or is the actual DataFrame being passed in? Hence, if I perform operations on the DataFrame within the function, will I be changing the original (because the references are still inta...
WhiteDillPickle
1

votes
1

answer
33

Views

Arrow function within jQuery map

I'm trying to use an arrow function within jQuery's map function. With the following testTitlesText is the correct length but each string is empty: let testTitles = $(panelBody).find('h4'); let testTitlesText = $(testTitles).map(testTitle => $(testTitle).text()); My ES6 transpiling is working, and j...
Ted Fitzpatrick
1

votes
2

answer
156

Views

A function composition operator in Python

In this question I asked about a function composition operator in Python. @Philip Tzou offered the following code, which does the job. import functools class Composable: def __init__(self, func): self.func = func functools.update_wrapper(self, func) def __matmul__(self, other): return lambda *args,...
RussAbbott
-1

votes
0

answer
21

Views

Invalid output for SHA1 implementation

For a personal project i require to implement the SHA1 function, the project will not be used for security purposes and so the security of this code is not a concern. I've been using RFC 3174 documentation, wikipedia and various stackoverflow q's to write and now debug why the output is incorrrect....
euan jones
1

votes
3

answer
45

Views

Javascript functions with optional first parameter, but passed second parameter [duplicate]

This question already has an answer here: Pass only the second argument in javascript 2 answers Allow either named arguments or positional arguments in Javascript 3 answers Let's say I have a function myfunc that can take up to two parameters: arg1 and arg2: var myfunc = function (arg1,arg2) { con...
jane
1

votes
2

answer
42

Views

Send a string array to a function by pointer or pointer-to-pointer with mem alloc?

Both of these functions fill the TCHAR sStringA and sStringB. The question is which one is preferred and more efficient in returning a result? #include #include void FunctionA(TCHAR *sString1, DWORD dwLen) { _tcscpy_s(sString1, dwLen, L'String1'); return; } void FunctionB(TCHAR **sString2, DWORD d...
JeffR
1

votes
1

answer
21

Views

R - If statement function to set value of new column

I have 2 columns pos and neg, each with a integer value. I would like to create a new column score, with each element of this column given a value of: 1 if pos > neg 0 if pos = neg -1 if pos < neg What would be the best way to do this? I am new to creating functions in R, so any help or direction i...
leftail
1

votes
1

answer
22

Views

'Update' some arguments in user defined functions in R

Assume we have a user defined function in R with many (> 20) function arguments. None of these arguments have pre-defined standard values (e.g. arg1 = 10). Simplified example: foo [1] 10 Note that here value = 2 since this was already specified for the object bar and only increment changes.
Frederick
1

votes
2

answer
72

Views

Haskell Nested List Comprehensions

I am studying for an exam and I am looking at an example of nested list comprehensions from the book 'Learn you a Haskell', and I was hoping if anyone could explain me step by step how to analyze it and come out with its output. let xxs = [[1,2,3],[2,3,4],[4,5]] [ [ x | x
wwww
1

votes
3

answer
44

Views

How to make the code in my function return editted dataframes

I am attempting to use ifelse statements in R to add a specific prefix to my dataframes. I have two issues with my code at the moment. 1) When I try to wrap this in a function it does not return the edited dataframes. 2) the no = parameter of the ifelse statement I have put in repeats itself, how...
Krutik
1

votes
3

answer
51

Views

A function always returns nil, due to misplacement of statements assigning values

In such a function I get a nil value but I do not understand why. The code in the middle returns an image (and I'm sure about it, I've also checked with some print statements). I do not know how is it possible that it always returns nil. It is like it ignores all the code running in the middle and c...
Niccolò Diana
1

votes
1

answer
132

Views

what is function scoped variables (var) and block scoped variables in es6?

I am new to javascipt as I have started learning js now, I am pretty confused with var that is said to be function scoped and block scoped; If so then how do we access them outside of that function!? lets say i want to use it from another class (I don't know maybe by creating some object or whatever...
Imran
1

votes
2

answer
77

Views

Why isn't function call an lvalue

This should be pretty obvious, but I could not any normative reference in the Standard explicitly that function call is (not) an lvalue. There is somewhat related question, but it's about C++ and no references is provided. Looking through 6.5.2.2(p5) Function calls the only I could find is If the e...
Some Name
1

votes
2

answer
38

Views

Access an internal function within an array of functions

I have the following code, it is a variable that has an array of functions, but I can not access them, send an error. What I need between them is help but send me an error when trying to access one of them within the other. var mivarobject = function(){ this.helpers = { function1: function(){ return...
Lenin Zapata
1

votes
3

answer
50

Views

Javascript: Loop Through Two Arrays and Sum Elements in Array Via Function

I have the following problem: Suzuki is a monk who climbs a large staircase to the monastery as part of a ritual. Some days he climbs more stairs than others depending on the number of students he must train in the morning. He is curious how many stairs might be climbed over the next 20 years and h...
PineNuts0
1

votes
3

answer
44

Views

Count all products with search function

I’ve been trying to call a function and it just doesn’t seem to work. So, this is function count_all_products_q. This is needed for pagination. function count_all_products_q($options=[]) { global $db; $visible = $options['visible'] ?? false; $search_statement = isset($_POST['search']) ? $_POST['...
Mantykora 7
1

votes
1

answer
32

Views

Is there a possibility to find unused functions in PhpStorm project (procedural)

I'm on a big procedural project existing since years and I want to clean up my code. I want to find all unused functions (not methods, it's a procedural project) I'm using PhpStorm and only found a function to look for unused methods, but not working with functions. I would like something like a lis...
BixEnte1
1

votes
1

answer
59

Views

Tensorflow: Sigmoid cross entropy loss does not force network outputs to be 0 or 1

I would like to learn image segmentation in TensorFlow with values in {0.0,1.0}. I have two images, ground_truth and prediction and each have shape (120,160). The ground_truth image pixels only contain values that are either 0.0 or 1.0. The prediction image is the output of a decoder and the last tw...
Fábio
1

votes
3

answer
40

Views

How to move multiple variables from a function into the global scope?

I'm new to python and I'm working on creating a monopoly like game and am working on the settings aspect of the program and I have a function that asks the user what they want to put in for each setting I am then using another function to import those settings to a text file so they can be stored fo...
warherolion
1

votes
2

answer
23

Views

js Setting function as variable or anonymous function returning the function

Okay, so I was wondering something. I just saw the following code: transform = function(e) { return Math.log(e); } But when I do the following code, it works the exact same way transform = Math.log; Is there any reason why you would use the upper one instead of the lower one?
Joshua Bakker
1

votes
5

answer
54

Views

Can I call a Python function without brackets, like a shell command. If so, how?

First time posting here, so apologies if I don't follow formatting guidelines or anything. I'm writing a terminal-like utility tool for, among other things, bulk file editing. My goal was to have every function be three letters ling, a bit like in Assembly. For example, mkd('yeet') makes a directo...
Walrus Gumboot
1

votes
3

answer
36

Views

Function does not push to the empty array to create list. How to fix this

I am trying to add items to the hobbies list via function call. But it's not added and i have been getting empty array all the time. There is something silly I am missing. Can you some please guide me to resolve this. I am including all code I am working on. I have tried calling the function like. p...
vsoni
1

votes
3

answer
57

Views

What exactly is a pure function when we are talking about a function within a function

I've learned that a pure function is a function that doesn't alter global state, period. If this is true, functions within functions can alter the state of the outer function and still be pure, correct? Example: function func1() { let name = 'My Name' func2() function func2() { // alter name here....
0oxl1
1

votes
1

answer
38

Views

Get Total Hours From Excel TEXT Function

I have a column in my worksheet that is a subtraction of 'End Time' and 'Start Time', giving me the total number of hours:minutes:Seconds during. Sample Input: Start Time: 15/04/2019 1:38:00 PM End Time : 18/04/2019 3:00:00 PM Basic subtraction gives me the right value i.e. 73:22:00 However for...
Noman Amir
1

votes
2

answer
58

Views

Using function in Python to list folder names

I have created a program that creates a function to list the contents of an arbitrary number of folders. The parameter list of the function will be an List of folder names in the program. The return value of the function will be a Dictionary where the key is the folder, and the value is a list of th...
thefence2113
1

votes
1

answer
47

Views

Adding /*const*/ instead of const qualifier to char * param in function prototype

I am facing a function which takes a pointer to a char array but it performs only read operations on the mem the char * points to. I could add const to the prototype directly before the char * parameter, but this would break the rest of the non const-correct code. I decided to add a comment /*const*...
pqans
1

votes
3

answer
45

Views

How to access variables from a closed Javascript function?

Suppose I have a function in my html file like ;(function(){ function execute(output) { return output; } })(); and then another one ;(function(){ console.log(execute('test')); })(); Now I get ReferenceError: execute is not defined How can I access that execute function if it's contained in another...
0

votes
0

answer
15

Views

Preparing a query doesn't work inside a function [duplicate]

This question already has an answer here: How to dynamically build queries with PDO 2 answers Which tokens can be parameterized in PDO prepared statements? 3 answers I want to run a query to my database and test if the information the user submits is the same as in the database. $name = $_POST['na...
Sampo Lahti
0

votes
0

answer
21

Views

User defined Mysql Functions in where condition Fails

I have created Mysql function which gives result integer or NULL. It works fine for all values. If use this function in simple query it aslo works as expected like following query : select distinct(hsd.hotel_id) from hotel_season_detail hsd where '2019-04-26' BETWEEN hsd.season_fromdate and hsd.se...
Nikhil Lende
0

votes
0

answer
14

Views

How to call a function from within a class? error is “X object has no attribute Y”

I'm a hobbyist programmer so I apologise if this seems a simple question. When I click on a button a function is called. The function though doesn't appear to have the info it needs to complete properly. I've tried various things including sending the CodeBox object but they have their own errors...
robster
2

votes
3

answer
31

Views

Basic even or odd question. Complete the isLastEvenOdd function below

Complete the isLastEvenOdd function below. The function should: Take one input parameter, an array of numbers and return the string 'even' or 'odd' based on whether the last item in the array is even or odd. I tried this: function isLastEvenOdd(numArray) { if (numArray %2===0) { return 'even' } else...
ferncodes
0

votes
1

answer
17

Views

How can i withdraw function open_restaurant()?

I need to withdraw function in class. I tried to type name of function, but get mistake: NameError: name 'open_restaurant' is not defined class Restaurant(): '''описание ресторана''' def __init__(self, restaurant_name, cuisine_type): '''Инициализирует атрибуты...
mash_
-1

votes
2

answer
20

Views

integrating SetTimeOut function after button click

I have created a snippet of code that changes the state from display:block to display:none by using an onClick element. My goal is to delay the change in state, for a few seconds whilst an animation effect occurs. This snippet of code below is what I am currently using to change the state of the el...
1

votes
1

answer
1.3k

Views

Optimal Length of a Python Function (Style) [closed]

Perhaps this is not the correct place to ask this question, and part of me thinks that there is no real answer to it, but I'm interested to see what experienced Python users have to say on the subject: For maximum readability, concision, and utility, what is a range for an optimal length of a Pyth...
austin_sherron
1

votes
3

answer
32

Views

How can I pass a function to click handler in the correct context?

I have to get an argument value from the function inside the onlick property of a button, but the function (this.getListItemId(itemId)) which makes use of this argument is not inside of the context from where the button is. The button is inside a child function (this.renderVideoListTemplate()) whic...
Arthur Muller

View additional questions