This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.caller = function (arguments) { | |
| if (arguments.callee.caller == null) { | |
| console.log('Caller: Global scope'); | |
| } else { | |
| console.log('Caller: ' + arguments.callee.caller.name); | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function fibonacci(n) { | |
| if (n == 0) return 0; | |
| if (n == 1) return 1; | |
| if (fibonacci.cache[n] > 0) return fibonacci.cache[n]; | |
| return fibonacci.cache[n] = fibonacci(n - 1) + fibonacci(n - 2); | |
| } | |
| fibonacci.cache = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getRandomElement(arr) { | |
| return arr[Math.floor(Math.random() * arr.length)]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getRandomInt(min, max) { | |
| return Math.floor(Math.random() * (max - min + 1)) + min; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function factorial(n) { | |
| if (n == 0 || n == 1) return 1; | |
| if (factorial.cache[n] > 0) return factorial.cache[n]; | |
| return factorial.cache[n] = factorial(n - 1) * n; | |
| } | |
| factorial.cache = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| on floor(x) | |
| set y to x div 1 | |
| if x < 0 and x mod 1 is not 0 then | |
| set y to y - 1 | |
| end if | |
| return y | |
| end floor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| on ceil(x) | |
| set y to x div 1 | |
| if x > 0 and x mod 1 is not 0 then | |
| set y to y + 1 | |
| end if | |
| return y | |
| end ceil |