Skip to content

Instantly share code, notes, and snippets.

//My Programming Goals - Filter
/*
Create a function that consumes goalsArray, filters out any irrelevant goals, adds any
programming goals you may have that are unlisted and returns the new list in alphabetical order.
You must use the Array.filter() function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
Array.filter() takes a callback function as an argument. That's right, you are passing in an a function as an argument to another function! This callback function will tell you how you want to filter each entry in goalsArray
*/
/*
Compare Objects
Consider the following example.
{ name: 'zeke' } === { name: 'zeke' }
What do you think the output will be? You might assume `true`. It is, however, false. This isn't a mistake, its intentional. Every object is unique from every other object. The usefulness of this will become clear over time. But, it does make it difficult to know if objects contain the same data.
Right now you're going to write a function that determines if two objects contain the same data.
//Complete Reverse FizzBuzz()
//The function should accept a number n, and console.log() all the numbers between 1-n. Any numbers divisible by 3 should say "Fizz", numbers divisible by 5 should say "Buzz" and numbers divisble by 15 should say 'Fizzbuzz'
//eg FizzBuzz(16) => 16, FIZZBUZZ, 14, 13, FIZZ, 11, BUZZ, FIZZ, 8, 7, FIZZ, BUZZ, 4, FIZZ, 2, 1
var FizzBuzz = function(n) {
var phraseToPrint = '';
for (var i = n; i > 0; i--) {
if (i % 3 === 0) phraseToPrint += 'FIZZ';
if (i % 5 === 0) phraseToPrint += 'BUZZ';
if (i % 3 !== 0 && i % 5 !== 0) phraseToPrint = i;
/*
PRIME CHECK
Create a function that takes a number as an input and returns True if the input is prime and false if it isn't
*/
function isPrime(num) {
for (var n = 2; n < num; n++) {
if (num % n === 0) return false;
return true;
/*
BUBBLE SORT
The Bubblesort Algorithm is one of many algorithms used to sort a list of similar items (e.g. all numbers or all letters) into either ascending order or descending order. Given a list (e.g.):
[9,7,5,3,1,2,4,6,8]
To sort this list in ascending order using Bubblesort, you first have to compare the first two terms of the list. If the first term is larger than the second term, you perform a swap. The list then becomes:
[7,9,5,3,1,2,4,6,8] // The "9" and "7" have been swapped because 9 is larger than 7 and thus 9 should be after 7
/*
CAN YOU TAKE ME HIGHER?
Create an elevator function that takes a single number input representing a floor destination.
If the destination is above the current floor, log "Going up!" to the console and log a "Ding!" + floor number for each floor it passes. When you've reached the destination, log "Doors open". The current floor should be changed to represent the position of the elevator
If the destination is less than the current floor, log "Going down!" and log a "Ding!" message for each floor you pass down. Similarly log a "Doors open" message when you've reached your destination
/*
Complete the two functions below. Both take 3 Numbers. getMedian() will return the Median (middle value) of the 3 numbers, while getMean will return the average. If not all the arguments are numbers, the function should return an error message, prompting the user to try again with proper inputs.
*/
var getMedian = function(a, b, c) {
// if typeof for a, b, c are not numbers then return an error
if (typeof a !== "number" || typeof b !== "number" || typeof c !== "number") {
return "one of those is not a number"}
var sortedArr = [a];
/*
Sniping Bond
DO NOT RUN THE CODE YET
Look at each of the Bond Villain IIFEs inside the badGuys function.
For each villain, write a prediction about whether bond (007) will be passed into the functions scope. Finally run the functions, and consider why or why not your predictions matched.
Reading:
IIFE : https://developer.mozilla.org/en-US/docs/Glossary/IIFE
/*
Frequency Analysis
Write a function that takes a string of text (containing ONLY lowercase letters)
and returns an object containing the normalized frequency for each letter.
To find a letter's normalized frequency, divide the number of that letter's occurence by the total character length of the string.
Example
var testStr = 'abca';
/*
EVEN SPEECH
Create a function that takes a string of words (no punctuation, each word is seperated by a space) and returns the string with only words of an even length. Any words with an odd length should have their last letter duplicated to even it out
eg)
evenIt('Hello my name is Karen') ==> 'Helloo my name is Karenn'
*/