Skip to content

Commit af55d75

Browse files
authored
Create mod.js
0 parents  commit af55d75

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

mod.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function internal(shouldReturnValue, count, testFunction) {
2+
if (testFunction === undefined) {
3+
testFunction = count;
4+
count = 1000;
5+
}
6+
7+
let currentValue;
8+
const first = testFunction();
9+
10+
for (let index = 0; index < count; index++) {
11+
currentValue = testFunction();
12+
13+
if (currentValue !== first) {
14+
return shouldReturnValue ? currentValue : false;
15+
}
16+
}
17+
18+
return shouldReturnValue ? first : true;
19+
}
20+
21+
const stableFunction = internal.bind(null, false);
22+
stableFunction.returnValue = internal.bind(null, true);
23+
24+
export default stableFunction;

0 commit comments

Comments
 (0)