Skip to content

Instantly share code, notes, and snippets.

/*
ATTENDENCE CHECK
Create a function that takes a weekday String as an argument. It then iterates over the classRoom array
and returns an array of all the students present for class on that weekday
*/
var classRoom = [
{
/*
FOREIGN LOOPS
Create a function that takes an animal name and iterates over the petSounds array and logs all the international sounds that animal makes to the console along with the country of origin. The log should follow the format "[animal]s in [country] say [sound]"
eg)
makeNoise('dog') ==> 'Dogs in America say Woof! Woof',
'Dogs in Germany say Wau! Wau',
....
'Dogs in Algeria say Wuaf Wuaf!'
// *** TALES OF TRUTHY AND FALSEY ***
// INTRODUCTION
// As you know, conditional statments are a fundamental part of programming:
// if (condition) {
// do this;
// } else {
// do that;
// }
//Bool School
//Look at all the truthy/falsey values nested in the if statement. We want the truthCheck() function to evalutate to true. For any values that need to change, put a ! in front of them to flip their Boolean value
// eg !true === false and !false === true
var truthCheck = function() {
/*
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'
*/
/*
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';
/*
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
/*
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];
/*
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
/*
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