Skip to content

Commit 6fda832

Browse files
author
Devendra Parmar
committed
Solved the two questions of the JavaScript
1. Clone a given regular expression 2. Get the first non null arguments from the given
1 parent 9304e79 commit 6fda832

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Write a JavaScript program to clone a given regular expression.
2+
3+
const cloneRegExp = () => new RegExp(regExp.source, regExp.flags);
4+
5+
const regExp = /lorem ipsum/gi;
6+
console.log(regExp);
7+
8+
const regExp2 = cloneRegExp(regExp);
9+
console.log(regExp2);

October/GetTheFirstNonNullArgument.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Write a JavaScript program to get the first non-null / undefined argument.
2+
3+
const coalesce = (...args) => args.find((_) => ![undefined, null].includes(_));
4+
5+
console.log(coalesce(null, undefined, "", NaN, "abcd"));

0 commit comments

Comments
 (0)