Skip to content

Instantly share code, notes, and snippets.

@mmloveaa
mmloveaa / 4-5
Last active April 5, 2016 16:49
4-5
Complete the given function growth that will calculate how many years until a town reaches a given population. The population will begin at a given start population. At the end of each year, the population will grow by a given percent, and then the population will change by a constant value called aug (inhabitants coming or leaving each year). Calculate how many years until it reaches the given goal population.
Note: Population should always be an integer, so always remove any decimal portion after each year. (Always round down)
Input Format:
The function will have 4 arguments
start - the initial population
percent - the percentage of population growth each year. (ex: 2 represents 2% growth)
aug - the constant number of inhabitants coming or leaving each year
goal - the population to meet or exceed
@mmloveaa
mmloveaa / 4-4 Q12 Mutation
Last active April 7, 2016 21:08
4-4 Q12 Mutation
Mutations
Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.
For example, ["hello", "Hello"], should return true because all of the letters in the second string are present in the first, ignoring case.
The arguments ["hello", "hey"] should return false because the string "hello" does not contain a "y".
Lastly, ["Alien", "line"], should return true because all of the letters in "line" are present in "Alien".
Remember to use Read-Search-Ask if you get stuck. Write your own code.
@mmloveaa
mmloveaa / 4-4 Q11 Slasher Flick
Last active April 5, 2016 06:46
4-4 Q11 Slasher Flick
Slasher Flick
Return the remaining elements of an array after chopping off n elements from the head.
The head means the beginning of the array, or the zeroth index.
Remember to use Read-Search-Ask if you get stuck. Write your own code.
using splice
@mmloveaa
mmloveaa / 4-4 FCC Q10 Chunky Monkey
Last active April 5, 2016 06:18
4-4 FCC Q10 Chunky Monkey
Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array.
Remember to use Read-Search-Ask if you get stuck. Write your own code.
Here are some helpful links:
Array.push()
Array.slice()
function chunkArrayInGroups(arr, size) {
@mmloveaa
mmloveaa / 4-4 FCC Q9 -Truncate a string
Last active April 5, 2016 02:43
4-4 FCC Q9 -Truncate a string
Truncate a string
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a ... ending.
Note that inserting the three dots to the end will add to the string length.
However, if the given maximum string length num is less than or equal to 3, then the addition of the three dots does not add to the string length in determining the truncated string.
Remember to use Read-Search-Ask if you get stuck. Write your own code.
Here are some helpful links:
@mmloveaa
mmloveaa / 4-4 FCC Q8 - Repeat a string
Last active April 5, 2016 01:07
4-4 FCC Q8 - Repeat a string
Repeat a string repeat a string
Repeat a given string (first argument) num times (second argument). Return an empty string if num is a negative number.
Remember to use Read-Search-Ask if you get stuck. Write your own code.
Here are some helpful links:
Global String Object
@mmloveaa
mmloveaa / 4-4 Freecodecamp Q7 Confirm Ending
Last active April 5, 2016 01:02
4-4 Freecodecamp Q7 Confirm Ending
Repeat a string repeat a string
Repeat a given string (first argument) num times (second argument). Return an empty string if num is a negative number.
Remember to use Read-Search-Ask if you get stuck. Write your own code.
Here are some helpful links:
Global String Object
@mmloveaa
mmloveaa / 4-4 FCC Q6 Return Largest Numbers in Arrays
Last active April 5, 2016 01:03
4-4 FCC Q6 Return Largest Numbers in Arrays
Check if a string (first argument, str) ends with the given target string (second argument, target).
Remember to use Read-Search-Ask if you get stuck. Write your own code.
Here are some helpful links:
String.substr()
function confirmEnding(str, target) {
// "Never give up and good luck will find you."
@mmloveaa
mmloveaa / 4-4 Freecodecamp Q5
Last active April 4, 2016 23:00
4-4 Freecodecamp Q5
Return Largest Numbers in Arrays
Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.
Remember, you can iterate through an array with a simple for loop, and access each member with array syntax arr[i].
Remember to use Read-Search-Ask if you get stuck. Write your own code.
function largestOfFour(arr) {
for(var i=0 ; i < arr.length; i++) {
arr[i].sort(function(a,b) {
@mmloveaa
mmloveaa / 4-4-Title case- FreeCodeCamp Q3
Last active April 5, 2016 02:25
4-4-Title case- FreeCodeCamp Q3
Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case.
For the purpose of this exercise, you should also capitalize connecting words like "the" and "of".
Remember to use Read-Search-Ask if you get stuck. Write your own code.
function titleCase(str) {
var arr = str.split(' ');
var arr1 = [];