Skip to content

Commit 71f9807

Browse files
author
Devendra Parmar
committed
Solved the two questions of the JavaScript
1. Create a function that accepts the nth arguments from the given function 2. Remove the event listener
1 parent d6bdcdf commit 71f9807

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Write a JavaScript program to create a function that gets the argument at index n. If n is negative, the nth argument from the end is returned.
2+
3+
const nthArgs =
4+
(n) =>
5+
(...args) =>
6+
args.slice(n)[0];
7+
8+
const third = nthArgs(2);
9+
10+
third(1, 2, 3);
11+
third(1, 2);
12+
13+
const last = nthArgs(-1);
14+
console.log(last(1, 2, 3, 4, 5));

October/RemoveEventListener.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Write a JavaScript program to remove an event listener from an element.
2+
3+
const off = (el, evt, fn, opts = false) => {
4+
el.removeEventListener(evt, fn, opts);
5+
};
6+
7+
const fn = () => console.log("!");
8+
9+
document.body.addEventListener("click", fn);
10+
11+
console.log(off(document.body, "click", fn));

0 commit comments

Comments
 (0)