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
Copy file name to clipboardExpand all lines: Bit-Manipulation/GrayCodes.js
+6-2Lines changed: 6 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,8 @@
1
-
// To generate Gray codes using bit manipulation in JavaScript, we can create a function that takes an integer n as input and returns an array of Gray codes up to 2^n - 1
1
+
/**
2
+
* Generates a Gray code sequence for the given number of bits.
3
+
* @param {number} n - The number of bits in the Gray code sequence.
4
+
* @returns {string[]} - An array of Gray codes in binary format.
5
+
*/
2
6
functiongenerateGrayCodes(n){
3
7
if(n<=0){
4
8
return[0]
@@ -16,4 +20,4 @@ function generateGrayCodes(n) {
16
20
returngrayCodes
17
21
}
18
22
19
-
export{generateGrayCodes}// Export the function for testing
0 commit comments