-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
75 lines (54 loc) · 1.65 KB
/
Copy pathfunctions.js
File metadata and controls
75 lines (54 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Q. What will be output
// function normalFn(){
// console.log(arguments)
// }
// normalFn("hello")
//===========================================================
//Q. Check if a string is palindrome
//Ans.
// function isPalindrome(str) {
// // Step 1: Normalize the input
// const cleaned = str.toLowerCase().replace(/[^a-z0-9]/g, "");
// // Step 2: Two-pointer approach
// let left = 0;
// let right = cleaned.length - 1;
// while (left < right) {
// if (cleaned[left] !== cleaned[right]) {
// return false;
// }
// left++;
// right--;
// }
// return true;
// }
// console.log(isPalindrome("A man a plan a canal Panama")); // true
// console.log(isPalindrome("madam")); // true
// console.log(isPalindrome("hello")); // false
// console.log(isPalindrome("RaceCar!")); // true
// console.log(isPalindrome("Was it a car or a cat I saw?")); // true
//===========================================================
// Q. Write a function that only runs once
//Ans.
// function once(fn) {
// let done = false;
// let result;
// return function (...args) {
// if (!done) {
// result = fn.apply(this, args);
// done = true;
// }
// return result;
// };
// }
//===========================================================
//Q. Write pipe() function
//===========================================================
//Q.Polyfill for bind()
// Ans.
// Function.prototype.myBind = function (context, ...boundArgs) {
// const fn = this;
// return function (...args) {
// return fn.apply(context, [...boundArgs, ...args]);
// };
// };
//===========================================================