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 3fa7a87 commit 9b254a6Copy full SHA for 9b254a6
scripts/algorithms/I/Implement Rand10 Using Rand7/Implement Rand10 Using Rand7.js
@@ -0,0 +1,19 @@
1
+// Runtime: 86 ms (Top 60.46%) | Memory: 49.50 MB (Top 76.74%)
2
+
3
+/**
4
+ * The rand7() API is already defined for you.
5
+ * var rand7 = function() {}
6
+ * @return {number} a random integer in the range 1 to 7
7
+ */
8
+var rand10 = function() {
9
+ while (true) {
10
+ const num1 = rand7() - 1;
11
+ const num2 = rand7();
12
13
+ const combinedNum = num1 * 7 + num2;
14
15
+ if (combinedNum <= 40) {
16
+ return (combinedNum % 10) + 1;
17
+ }
18
19
+};
0 commit comments