Skip to content

Instantly share code, notes, and snippets.

View harrisonmalone's full-sized avatar

Harrison Malone harrisonmalone

View GitHub Profile

Math practise

Some really nice resources for maths wre written up by Gretchen last week. It contains examples as well as questions which are answered below.

  1. What kind of graph is this?
directed because it has the arrows, unweighted because there's no numbers 

Morning challenge

Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.

Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Polycarpus inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.

For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".

Recently, Jonny has heard Polycarpus's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Polycarpus remixed. Help Jonny restore the original song.

function songDecoder(song){
song = song.split("WUB")
const newSong = song.filter(function(word) {
return word !== ''
}).join(" ")
return newSong
}
console.log(songDecoder("WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB"))
@harrisonmalone
harrisonmalone / dom.js
Last active November 25, 2018 22:10
challenge 2 in my js github content
// Here are some challenges. Solve them from top to bottom
// Ex 1. Read the content of the email input
const email = document.querySelector('#email')
email.value
// Ex 2. Fill the content of the email input with your email
email.value = "[email protected]"
// Ex 3. Replace the email hint (next to the input) with 'This is my email now'
// The text should be emphasized using a <strong> tag
const hint = document.querySelector('#email-hint')
hint.innerText = ''
// Write a factory function (to create objects) that takes one argument. It should use that argument to set the value of the first key of the object. The second key should be given the value ‘red’.
function Car(brand) {
function printCar() {
console.log(`the brand of car is ${this.brand}`)
}
return {
brand: brand,
color: 'red',
printCar: printCar
}
@harrisonmalone
harrisonmalone / index.html
Created November 26, 2018 11:05
pokedex api code day 1
<!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>
</head>
<body>
<h1>Pokemon list</h1>
@harrisonmalone
harrisonmalone / comparing-squared-arrays.js
Last active November 27, 2018 11:47
morning challenge 27/11, nice use case for sort and looping through two arrays
// Given two arrays a and b write a function comp(a, b) (compSame(a, b) in Clojure) that checks whether the two arrays have the "same" elements, with the same multiplicities. "Same" means, here, that the elements in b are the elements in a squared, regardless of the order.
// Examples
// Valid arrays
// a = [121, 144, 19, 161, 19, 144, 19, 11]
// b = [121, 14641, 20736, 361, 25921, 361, 20736, 361]
// comp(a, b) returns true because in b 121 is the square of 11, 14641 is the square of 121, 20736 the square of 144, 361 the square of 19, 25921 the square of 161, and so on. It gets obvious if we write b's elements in terms of squares:
// a = [121, 144, 19, 161, 19, 144, 19, 11]
@harrisonmalone
harrisonmalone / creating-number-range-eloquent-js.js
Last active November 27, 2018 11:48
nice challenge that would work in any language
// As a bonus assignment, modify your range function to take an optional third argument that indicates the “step” value used when building the array. If no step is given, the elements go up by increments of one, corresponding to the old behavior. The function call
// range(1, 10, 2)
// should return
// [1, 3, 5, 7, 9]
// Make sure it also works with negative step values so that
const express = require('express')
const app = express()
// allowed us to do post requests, middleware, will go into more tomorrow
app.use(express.json())
const pokemon = [
{
id: 1,
name: 'pikachu',
test()
// when we invoke this function it breaks
// the variable test (const test) is hoisted but not what's stored in it
// function expressions aren't hoisted
testTwo()
// whereas because testTwo is a function declaration it doesn't break when we invoke it above the actual declaration
// the whole function declaration is hoisted and we can use it anywhere in the global scope
// example of function expression
const test = function() {