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 phi(table) { | |
| return (table[3] * table[0] - table[2] * table[1]) / | |
| Math.sqrt((table[2] + table[3]) * | |
| (table[0] + table[1]) * | |
| (table[1] + table[3]) * | |
| (table[0] + table[2])); | |
| } |
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 countChar(str, char) { | |
| var count = 0; | |
| for(var i = 0; i < str.length; i++) { | |
| if(str.charAt(i) === char) count++; | |
| } | |
| return count; | |
| } | |
| function countBs(str) { | |
| return countChar(str, "B"); |
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 isEven(num) { | |
| if(num === 0) return true; | |
| else if(num === 1) return false; | |
| else if(num < 0) return isEven(-num); | |
| return isEven(num - 2); | |
| } |
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 min(a, b) { | |
| if(a < b) return a; | |
| else return b; | |
| } |
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 chessBoard(size) { | |
| var board = ""; | |
| for (var y = 0; y < size; y++) { | |
| for (var x = 0; x < size; x++) { | |
| if ((x + y) % 2 == 0) | |
| board += "#"; | |
| else | |
| board += " "; | |
| } | |
| board += "\n"; |
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 fizzBuzz() { | |
| for (var n = 1; n <= 100; n++) { | |
| var output = ""; | |
| if (n % 3 == 0) | |
| output += "Fizz"; | |
| if (n % 5 == 0) | |
| output += "Buzz"; | |
| console.log(output || n); | |
| } | |
| } |
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 drawTriangle() { | |
| for (var line = "#"; line.length < 8; line += "#") | |
| console.log(line); | |
| } | |
| //OUTPUT: | |
| //# | |
| //## | |
| //### | |
| //#### | |
| //##### |
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 rot13(str) { | |
| return str.split('').map(function(char) { | |
| var charCode = char.charCodeAt(); | |
| if(charCode >= 65 && charCode <= 90) { | |
| charCode = (charCode - 65 + 13) % 26 + 65; | |
| } | |
| return String.fromCharCode(charCode); | |
| }).join(''); | |
| } |
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 getIndexToIns(arr, num) { | |
| arr = arr.sort(function(a,b) { | |
| return a - b; | |
| }); | |
| for(var i = 0; i < arr.length; i++) { | |
| if(num <= arr[i]) { | |
| return i; | |
| } | |
| } | |
| return 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 destroyer(arr) { | |
| var args = Array.prototype.slice.call(arguments); | |
| var result = args[0].filter(function(num) { | |
| if(!args.includes(num)) { | |
| return num; | |
| } | |
| }); | |
| return result; | |
| } |
NewerOlder