You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**Exponentiation Operator (`**`)**: The exponentiation operator (`**`) was introduced to replace `Math.pow()`. It allows you to raise numbers to a power more easily.
3
+
3
4
-**Array.prototype.includes**: A new method for arrays to check if an element exists in the array. It is more readable than `indexOf()`.
-**`async`/`await`**: Introduced as a cleaner way to handle asynchronous code by using promises in a more synchronous-like manner. It improves code readability and reduces callback hell.
4
+
4
5
-**Object.entries() and Object.values()**: These methods provide an easy way to iterate over the properties and values of an object. `Object.entries()` returns an array of key-value pairs, while `Object.values()` returns an array of values.
6
+
5
7
-**String padding methods (`padStart()` and `padEnd()`)**: These methods allow you to pad the beginning or the end of a string with specified characters to ensure a specific string length.
8
+
6
9
-**Shared memory and atomics**: Introduced shared memory for use with Web Workers and atomics for controlling concurrent access to memory.
Given two strings s and t, determine if they are isomorphic.
3
+
4
+
Two strings s and t are isomorphic if the characters in s can be replaced to get t.
5
+
6
+
All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.
7
+
*/
8
+
9
+
/**
10
+
* @param {string} s
11
+
* @param {string} t
12
+
* @return {boolean}
13
+
*/
14
+
varisIsomorphic=function(s,t){
15
+
letmap=newMap();
16
+
17
+
letans="";
18
+
19
+
for(leti=0;i<s.length;i++){
20
+
letelementS=s[i];
21
+
letelementT=t[i];
22
+
// check if item already exists in map
23
+
if(map.has(elementS)){
24
+
// if yes => then add value corresponding to it in ans
25
+
ans+=map.get(elementS);
26
+
}else{
27
+
// if no => add[same index] it to map => then add value to string
28
+
if([...map.values()].includes(elementT)){
29
+
returnfalse;
30
+
}
31
+
map.set(elementS,elementT);
32
+
ans+=elementT;
33
+
}
34
+
}
35
+
console.log(ans);
36
+
37
+
if(ans===t)returntrue;
38
+
39
+
returnfalse;
40
+
41
+
};
42
+
43
+
lets1="paper";
44
+
lett1="title";
45
+
lets2="foo";
46
+
lett2="bar";
47
+
lets3="egg";
48
+
lett3="add";
49
+
lets4="badc";
50
+
lett4="baba";
51
+
52
+
// console.log(isIsomorphic(s1, t1));
53
+
// console.log(isIsomorphic(s2, t2));
54
+
// console.log(isIsomorphic(s3, t3));
55
+
console.log(isIsomorphic(s4,t4));
56
+
57
+
58
+
59
+
// intution
60
+
61
+
/* question says ki humko ekk string se dusti string bana k dekhna hai ki ban rhi hai k nhi
62
+
given ki hum second string k elements ko first string k elements se replacce krte jaye.
63
+
64
+
ek condition hai ki ek character ko ek value assign ho gy to vahi use hogi.
65
+
66
+
67
+
iske liye we will use a map
68
+
69
+
agar map mai value hai to usko use karenge
70
+
agar nhi hai to new use karenge
71
+
72
+
final jo string banegi usko second string se compare karenge for answer
0 commit comments