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
| //Coderbyte challenge | |
| var FirstReverse = function(str) { | |
| return str.split('').reverse().join(''); | |
| } | |
| FirstReverse('Test'); // -> tseT |
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
| // Calculate the last prime number under 1000 | |
| var isPrime = function(num) { | |
| if (num < 2) { | |
| return false; | |
| } | |
| for (var i = 2; i < num; i++) { | |
| if (num % i === 0) { | |
| return false; | |
| } |
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
| // Codeval problem to solve the sum of the first 1000 primes | |
| var isPrime = function(num) { | |
| if (num < 2) { | |
| return false; | |
| } | |
| for (var i = 2; i < num; i++) { | |
| if (num % i === 0) { | |
| return false; | |
| } |
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
| // Simple function for converting string to lowercase | |
| var textConvert = function(a){ | |
| if (typeof a == 'string') { | |
| $('body').append(a.toLowerCase() + '</br>'); | |
| } | |
| else {http://jsfiddle.net/user/dashboard/ | |
| $('body').append('Please input a string'); | |
| } | |
| }; |
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
| // Duplicate a numeric array | |
| var numArray = [1, 2, 3, 4, 5]; | |
| var duplicate = function(a) { | |
| for (var i = 0; i < 1; i++) { | |
| a = a + a; | |
| } | |
| return a; | |
| }; |
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
| // A simple modulus function | |
| var mod = function(a,b) { | |
| var c = Math.floor(a / b); | |
| var d = b * c; | |
| var e = a - d; | |
| return e; | |
| }; | |
| $('body').append(mod(25,5)); |
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
| // Program to take an array of the alphabet and pair every letter of the alphabet | |
| // with every other letter of the alphabet | |
| // First, we define the array | |
| var xyz = ['A','B','C','D','E','F','G','H','I','J','K','L','M', | |
| 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z']; | |
| // Output the solution with two loops |
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
| // isEven() recursion function to test if numbers are even | |
| // with the following rules | |
| // if n == 0, then it is even | |
| // if n == 1, then it is odd, and false | |
| // if n < 0, or negative, then we have a recursion that negates the number and restarts the function | |
| // otherwise, all other numbers will recursively test if they are even by subtracting -2 | |
| // until the program goes to the first two conditions | |
| // For really big numbers the stack overflows and the simpler n % 2 == 0 condition is more efficient | |
| function isEven(number) { |
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
| // My minimum function alternative to Math.min() | |
| function min(a,b) { | |
| if (a < b) | |
| return a; | |
| else | |
| return b; | |
| } | |
| console.log(min(0, 10)); |
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
| // Chessboard exercise | |
| var size = 8; | |
| var chess = ""; | |
| for (y = 0; y < size; y++) { | |
| for (x = 0; x < size; x++) { | |
| if ((x+y) % 2 == 0) | |
| chess += "#"; | |
| else | |
| chess += " "; |
NewerOlder