We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0ca18c2 commit eafa1b5Copy full SHA for eafa1b5
Bit-Manipulation/minMaxElement.js
@@ -0,0 +1,17 @@
1
+/**
2
+ * @author : nikgautamgithub
3
+ *
4
+ * Find max or min element using bit operators.
5
+ * @param {number} x - The input number to compare.
6
+ * @param {number} y - The input number to compare.
7
+ * @returns Min/Max Element
8
9
+ * @example
10
+ * const maxi = max(5,3) // Returns max number i.e. 5
11
+ * const mini = min(5,3); // Returns min number i.e. 3
12
+ */
13
+const max = (x, y) => x ^ ((x ^ y) & -(x < y ? 1 : 0));
14
+
15
+const min = (x, y) => y ^ ((x ^ y) & -(x < y ? 1 : 0));
16
17
+export { min, max };
0 commit comments