Skip to content

Instantly share code, notes, and snippets.

View Dylan-Thomson's full-sized avatar

Dylan Thomson Dylan-Thomson

  • RVShare
  • Cuyahoga Falls, OH United States
  • 09:01 (UTC -05:00)
View GitHub Profile
@Dylan-Thomson
Dylan-Thomson / phi.js
Created June 5, 2017 22:27
Phi - Eloquent JavaScript Chapter 4 Example
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]));
}
@Dylan-Thomson
Dylan-Thomson / countChar.js
Created June 5, 2017 17:56
CountChar - Eloquent JavaScript Chapter 3 Solution
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");
@Dylan-Thomson
Dylan-Thomson / isEven.js
Created June 5, 2017 17:55
isEven - Eloquent JavaScript Chapter 3 Solution
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);
}
@Dylan-Thomson
Dylan-Thomson / min.js
Created June 5, 2017 17:55
Minimum - Eloquent JavaScript Chapter 3 Solution
function min(a, b) {
if(a < b) return a;
else return b;
}
@Dylan-Thomson
Dylan-Thomson / chessBoard.js
Last active June 5, 2017 17:42
ChessBoard - Eloquent JavaScript Chapter 2 Solution
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";
@Dylan-Thomson
Dylan-Thomson / fizzBuzz.js
Created June 5, 2017 17:18
FizzBuzz - Eloquent JavaScript Chapter 2 Solution
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);
}
}
@Dylan-Thomson
Dylan-Thomson / drawTriangle.js
Last active June 5, 2017 17:17
Draw Triangle - Eloquent JavaScript Chapter 2 Solution
function drawTriangle() {
for (var line = "#"; line.length < 8; line += "#")
console.log(line);
}
//OUTPUT:
//#
//##
//###
//####
//#####
@Dylan-Thomson
Dylan-Thomson / rot13.js
Created June 5, 2017 15:23
FreeCodeCamp ROT13 Solution
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('');
}
@Dylan-Thomson
Dylan-Thomson / getIndexToIns.js
Created June 5, 2017 15:22
FreeCodeCamp GetIndextToIns Solution
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;
@Dylan-Thomson
Dylan-Thomson / destroyer.js
Created June 5, 2017 15:19
FreeCodeCamp Destroyer Exercise Solution
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;
}