Skip to content

Instantly share code, notes, and snippets.

/*
MARVEL CIVIL WAR
Given an Array of superhero objects, create a function that check if the heroes with a true "is_registered" property also have a "secret_identity". If they are unregistered, or registered without their secret identity, add them to a "Government Watch" array and log their "testify" functions to the console.
*/
//Superhero Super-Class Constructor
var Superhero = function(name, identity, registered) {
var hero = {
hero_name: name,
/*
REVERSE STRING
Create a function that takes a string of any length as input and returns that string reversed.
Use recursion ;)
*/
function reverseString(str){
var n = str.length-1;
/*
FIBONACCI
Create a function that takes a number n and returns the nth number in the Fibonacci sequence.
The Fibonacci sequence is a series of numbers, where each number is the sum of the two numbers preceding it.
Ex)
1, 1, 2, 3, 5, 8, 13, 21, 34, 55....
/*
EAT IT!
Create a function that will 'judge' the results of a competitive eating competition
There are 3 foods:
pizza: 2 points
hotdog : 3 points
cheeseburger : 5 points
//Animal constructor function
function Animal(species, call) {
this.species = species;
this.call = call;
this.speak = function (call) {
console.log("The " + this.species + " says " + this.call)
}
}
//The Animals. Follow the design pattern to make as many as you want and add them to the zoo
/*
Anagramatic
Write a function that takes in two strings and determines if they are anagrams of each other. Something is an anagram of something else if it is made up of the same characters.
For example ekez is an anagram of zeke. zkee is also an anagram of zeke.
Your function should return true or false.
anagram('zeke', 'hello world');
/*
PUSH POP
Write your own versions of Push and Pop
Push takes two arguments, an array, and a value to add to that array. The function should return the array modified to include the new value.
push([8,2,3,4], 5)
// -> [8,2,3,4,5]
/*
Check if Array is Sorted
Complete the function isSorted, which takes an array as inputed and outputs a boolean indicating if the array's contents are in ascending order.
isSorted([8,2,3,4])
// -> false
isSorted([2,3,4,8])
// -> true
/*
Advanced Counting
We're going to rewrite our countdown function, but this time let's support negative numbers. If you pass the function a positive number, it counts down to 1. If you pass the function a negative number, it should count up to -1. You can assume the function will never be passed 0.
Please complete this problem in 2 ways.
1. With a while loop
2. With a for loop
count(4)
/*
SHIFT DECK
Create a function, deckShift() that takes a number and a direction ('left' or 'right) and returns an array of cards shifted that many spaces in that direction. This function should not mutate the original deck variable.
Examples
deckShift(4, 'left') => [6,7,8,9,10,'J','Q','A',2,3];
deckShift(2, 'right') => ['K','A',2,3,4,5,6,7,8,9,10,'J','Q'];
*/
var deck = [2,3,4,5,6,7,8,9,10, 'J', 'Q', 'K', 'A'];