Skip to content

Instantly share code, notes, and snippets.

View MPKel's full-sized avatar

Michael Kelley MPKel

View GitHub Profile
@MPKel
MPKel / bloccit-rails-console-assignment
Created December 12, 2017 00:20
bloccit-rails-console-assignment
[13] pry(#<Post>):1> nesting
Nesting status:
--
0. main (Pry top level)
1. #<Post>
[14] pry(#<Post>):1> self.to_s
=> "#<Post:0x007f8e3e721a90>"
[15] pry(#<Post>):1> self.title = "New Main Post"
=> "New Main Post"
[16] pry(#<Post>):1> self.body = "New Body for Main Post"
@MPKel
MPKel / player-js-analysis.md
Last active October 9, 2017 20:22 — forked from R-V-S/player-js-analysis.md
player.js analysis
  1. This file declares a class, Player, instantiates it, and assigns it to a global player variable.
  2. The Player class contains four methods:
    • constructor()
    • playPause()
    • skipTo()
    • setVolume()
  3. The constructor() method sets initial values for the currentlyPlaying, playState, volume, and soundObject properties.
    • currentlyPlaying is set to the first item in album.songs.
    • The initial playState is "stopped".
  • The volume is set to the number 80.
@MPKel
MPKel / grokking.js
Created August 10, 2017 17:45
Challenge: analyze a most frequent word program
//function to parse the provided string of text and break it up into an array of words or tokens using RegEx.
function getTokens(rawString) {
// NB: `.filter(Boolean)` removes any falsy items from an array
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean).sort();
}
function mostFrequentWord(text) {
//creates a variable 'words' to hold the array
//created by getTokens()
const words = getTokens(text);
const studentData = [
{
name: 'Tim',
status: 'Current student',
course: 'Biology'
},
{
name: 'Sue',
status: 'Withdrawn',
course: 'Mathematics'
@MPKel
MPKel / key-deleter.js
Created August 9, 2017 10:09
Objects Practice
function keyDeleter(obj) {
delete obj.foo;
delete obj.bar;
return obj;
}
var sampleObj = {
foo: 'foo',
bar: 'bar',
@MPKel
MPKel / Thinkful-scope-Answers
Created August 7, 2017 18:20
Scope questions/answers
What is scope?
Put simply, scope is the availability of a variable within a program.
Scope determines which parts of a program have the ability to access and manipulate a variable.
A global variable is available for access/manipulation by all parts and collective files(*sometimes) of a program.
A local variable's access is restricted to the function or block within which it was declared.
Why are global variables avoided?
Global variables are avoided because they create the possibility of unexpected side effects,
namely the unintended manipulation of variables, which causes functions to become indeterminate.
@MPKel
MPKel / averaging.js
Created August 5, 2017 20:03
Loop Practice
function average(numbers) {
let holder = numbers[0];
for (let i = 1; i < numbers.length; i++){
holder += numbers[i];
}
return holder / numbers.length;
}
@MPKel
MPKel / copy-first-half.js
Created August 5, 2017 18:10
Array methods
function minusLastItem(array) {
array.pop();
return array;
}
function copyFirstHalf(array) {
return array.slice(0, (array.length/2 + 1));
}
@MPKel
MPKel / access-items.js
Created August 5, 2017 15:30
Array Practice
function accessFirstItem(array) {
return array[0];
}
function accessThirdItem(array) {
return array[2];
}
@MPKel
MPKel / computer-area.js
Last active August 4, 2017 21:11
string literal practice
function computeArea(width, height) {
let result = width * height;
return result;
// your code here
}
/* From here down, you are not expected to
understand.... for now :)