Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
is it possible to read two different values over one parameter in a function? I need to load two values in one parameter into a function.
Thank you for your help
Yes, it's possible. Simplest example:
function test(params) {
return params.first + params.second;
}
console.log(test({
first: 3,
second: 4
}));
If you care about the names, then:
function test(params) {
var {first, second} = params;
return first + second;
}
console.log(test({
first: 3,
second: 4
}));
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
How can i find the largest number from given digits?
For example:
const myFunction = input => {
return //im not sure how to produce what i need here.
}
myFunction(36);
//Should return 63
Is that you want?
function getMax(number) {
return parseInt(number.toString().split('').sort(function(a, b) { return b - a }).join(''));
}
console.log(getMax(36), getMax(128945));
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
The page just echoes the user input using GET. I have no idea on what concept to apply to detect if the user has alerted something
The easiest approach would probably be to replace the alert method with your own.
const log = [];
alert = function(alert) {
return (value) => {
log.push(value);
alert(value);
};
}(alert);
alert("Hello!");
console.log(log);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have been asked to show I have used these processes in my program but from looking up the definitions, I don't know what they mean. I am confident my program is complicated enough that it uses these processes, but I don't know exactly what they are. What would be an example of these processes used in javascript?
Unsure what you mean by custom function - but recursion is just a function that calls itself.
Example of recursion
countNumTimesToZero = (myNum, count = 0) => {
if (myNum - 1 === 0) return count + 1;
return countNumTimesToZero(myNum - 1, count + 1);
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to limit the execution of two different functions with the same throttle.
Let's say I have a function called A and another one called B.
I want to limit the number of executions of both of them so that if A is called at time 0, and the limit is 1000, B shouldn't get executed until after 1000ms has passed
what i did:
doubleThrottle = (action) => {
if (action)
return this.A()
return this.B()
}
let throttledUpdate = throttle(this.doubleThrottle, 1000, {'trailing': false})
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Hi this is a simple question. I was wondering is there any different when you declare something like this. Thanks
selectedData[key](val)
and
selectedData[key] = val
This line selectedData[key](val) is not a declaration, it's calling the function that is stored under the key key in the object selectedData and it's passing the parameter val to that function.
The other line selectedData[key] = val is assigning the value val to the key key in the object selectedData.
In the first case, you're calling whatever is in selectedData[key] as a function with val as an argument while in the second one you're assigning it.