function interview questions
Top function frequently asked interview questions
In one of my project source files, I found this C function definition:
int (foo) (int *bar)
{
return foo (bar);
}
Note: there is no asterisk next to foo
, so it's not a function pointer. Or is it?
What is going on here with the recursive call?
Source: (StackOverflow)
What is the difference between using call and apply to invoke a function?
var func = function(){
alert('hello!');
};
func.apply();
vs
func.call();
Are there performance differences between the two methods? When is it best to use call over apply and vice versa?
Source: (StackOverflow)
This question already has an answer here:
I often find myself confused with how the terms 'arguments' and 'parameters' are used. They seem to be used interchangeably in the programming world.
What's the correct convention for their use?
Source: (StackOverflow)
I want to create a function that performs a function passed by parameter on a set of data. How do you pass a function as a parameter in C?
Source: (StackOverflow)
Coming from a C# background the naming convention for variables and method names are usually either CamelCase or Pascal Case:
// C# example
string thisIsMyVariable = "a"
public void ThisIsMyMethod()
In Python, I have seen the above but I have also seen underscores being used:
# python example
this_is_my_variable = 'a'
def this_is_my_function():
Is there a more preferable, definitive coding style for Python?
Source: (StackOverflow)
Is there a way to allow "unlimited" vars for a function in JavaScript?
Example:
load(var1, var2, var3, var4, var5, etc...)
load(var1)
Source: (StackOverflow)
I've always handled optional parameters in Javascript like this:
function myFunc(requiredArg, optionalArg){
optionalArg = optionalArg || 'defaultValue';
//do stuff
}
Is there a better way to do it?
Are there any cases where using ||
like that is going to fail?
Source: (StackOverflow)
In this particular case, what options do I have to make these inputs call a function when I press Enter?
// HTML view //
<form>
<input type="text" ng-model="name" <!-- Press ENTER and call myFunc --> />
<br />
<input type="text" ng-model="email" <!-- Press ENTER and call myFunc --> />
</form>
// Controller //
.controller('mycontroller', ['$scope',function($scope) {
$scope.name = '';
$scope.email = '';
// Function to be called when pressing ENTER
$scope.myFunc = function() {
alert('Submitted');
};
}])
Source: (StackOverflow)
I would like a JavaScript function to have optional arguments which I set a default on, which gets used if the value isn't defined. In Ruby you can do it like this:
def read_file(file, delete_after = false)
# code
end
Does this work in JavaScript?
function read_file(file, delete_after = false) {
// Code
}
Source: (StackOverflow)
In Python, how do I get a function name as a string without calling the function?
def my_function():
pass
print get_function_name_as_string(my_function) # my_function is not in quotes
should output "my_function"
.
Is this available in python? If not, any idea how to write get_function_name_as_string
in Python?
Source: (StackOverflow)