Skip to content

Instantly share code, notes, and snippets.

View harrisonmalone's full-sized avatar

Harrison Malone harrisonmalone

View GitHub Profile
@harrisonmalone
harrisonmalone / index.html
Last active November 19, 2018 10:46
another example of using a input event listener to append text to the body of html, was also using this to test debugger
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="style.css">
<script defer src="script.js"></script>
</head>
def fibonacci(n, arr)
a = 0
b = 1
n.times do
temp = a
# sets temp to be 0, 1 on the second loop
a = b
# sets b to be 1, still 1 on the second loop, 2 on the third loop
b = temp + b
arr << a
def pig(sentence)
array_of_words = sentence.split(" ")
# here we split every word in the sentence
pig_array = array_of_words.map do |word|
letter = word[0]
# here we get the first letter of each word and store it
array_of_letters = word.split("")
# here we split each of the words into an array of letters
array_of_letters.shift
# we remove the first item from the array of letters
@harrisonmalone
harrisonmalone / demo.js
Last active November 21, 2018 11:04
excellent test for scope and the way javascript works
function getDemo(demo) {
const test = function() {
return demo + ' my friend'
}
// an anonymous function is assigned to a variable test
demo = demo + ' how are you'
// we do some string concatenation
// => "hi how are you"
return test()
// we return test() which invokes the function, as javascript goes from inner to outer scope demo within this function is "hello how are you" and it's concatenated with " my friend", this value is returned
@harrisonmalone
harrisonmalone / index.html
Last active November 21, 2018 11:09
using .fetch and .then to access data from a rails api built together in class
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="style.css">
<script defer src="main.js"></script>
</head>
// Pick any four digit number and do the following:
// Rearrange the string of digits to form the largest and smallest 4-digit numbers possible.
// Take these two numbers and subtract the smaller number from the larger.
// Suppose we choose the number 8082.
// 8820−0288=8532
// 8532−2358=6174
// 7641−1467=6174
// It hits 6174 and then stops.
// Count also how many iterations loops are required to get to this point.
// Bonus points for recognising what 6174 is.
const signature = [0,0,1]
for(x=2; x<10; ++x) {
let num = signature[x] + signature[x-1] + signature[x-2]
signature.push(num)
}
console.log(signature)
// If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
// Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in.
// Note: If the number is a multiple of both 3 and 5, only count it once.
function solution(number){
const arr = []
for(i = 1; i < number; i++) {
arr.push(i)
// convert base 10 to base 2
function baseTenToBaseTwo(baseTenValue) {
const baseTwoArr = []
let baseTwoValue = null
for(let i = 0; baseTwoValue < baseTenValue; i++) {
baseTwoValue = 2 ** i
baseTwoArr.push(baseTwoValue)
}
// this gives me an array of baseTwoValues (represented in decimal), when the baseTwoValue is greater than what baseTenValue is passed in our for loop ends