Skip to content

Instantly share code, notes, and snippets.

@productdevbook
Last active February 14, 2025 12:36
Show Gist options
  • Save productdevbook/3d09a136ec51f19bf78d601e0c042e86 to your computer and use it in GitHub Desktop.
Save productdevbook/3d09a136ec51f19bf78d601e0c042e86 to your computer and use it in GitHub Desktop.
fn
// #1
function logWrapper(fn: Function) {
return function (...args: any[]) {
console.log(`Calling function with args: ${args}`);
return fn(...args);
};
}
const multiply = (a: number, b: number) => a * b;
const loggedMultiply = logWrapper(multiply);
console.log(loggedMultiply(4, 5)); // "Calling function with args: 4,5" and
// #2
const sumFunction = new Function("a", "b", "return a + b;");
console.log(sumFunction(3, 5)); // 8
// #3
const storedFunction = `function greet(name) { return "Hello, " + name; }`;
const newFunction = new Function("name", storedFunction.split("{")[1].split("}")[0]);
console.log(newFunction("Ali")); // "Hello, Ali"
// #4
function hello() {
return "Merhaba, dünya!";
}
const funcAsString = hello.toString();
console.log(funcAsString);
/*
Çıktı:
function hello() {
return "Merhaba, dünya!";
}
*/
// #5
const numbers = [3, 5, 9, 1, 7];
console.log(Math.max.apply(null, numbers)); // 9
console.log(Math.min.apply(null, numbers)); // 1
// #6
function multiply(a: number, b: number) {
return a * b;
}
const double = multiply.bind(null, 2); // İlk parametre 2 olarak atanıyor
console.log(double(5)); // 10
console.log(double(10)); // 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment