Skip to content

Instantly share code, notes, and snippets.

@mmloveaa
mmloveaa / 4-4 freecodecamp Q4
Created April 4, 2016 17:38
4-4 freecodecamp Q4
Return the length of the longest word in the provided sentence.
Your response should be a number.
Remember to use Read-Search-Ask if you get stuck. Write your own code.
function findLongestWord(str) {
var arr = str.split(' ');
var max=0;
@mmloveaa
mmloveaa / 4-4 morning challenge
Last active April 4, 2016 17:21
4-4 morning challenge
All Rotations
Complete the function containsAllRotations that will determine if all rotations of a given string are found in a given array of strings. That array will be unordered, and there may be extra unneeded strings in there as well.
To rotate a string, move the first character to the end of the string. You may continue this process to see all possible rotations. ex: 'dog' --> 'ogd' --> 'gdo'
Note: The original un-rotated string must also be found in the array, as it is a possible rotation.
Input Format:
The function will have two arguments:
str - a string.
@mmloveaa
mmloveaa / 4-3 Drop it
Last active April 4, 2016 17:22
4-3 Drop it - freecodecamp
Drop the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true.
The second argument, func, is a function you'll use to test the first elements of the array to decide if you should drop it or not.
Return the rest of the array, otherwise return an empty array.
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
Here are some helpful links:
@mmloveaa
mmloveaa / 4-3 Regex - palindrome - Freecodecamp Q3
Last active April 4, 2016 17:41
4-3 Regex - palindrome - Freecodecamp Q3
function palindrome(str) {
str= str.toLowerCase().replace(/[^a-z0-9]/g,'')
//console.log("before strR: ", str)
var strR = str.split('').reverse().join('')
//console.log(strR)
return strR === str
}
palindrome("0_0 (: /-\ :) 0-0");
@mmloveaa
mmloveaa / 4-3 - Factorialize - Freecodecamp Q2
Last active April 4, 2016 17:41
4-3 - Factorialize - Freecodecamp Q2
function factorialize(num) {
var arr = []
for (var i=1; i<=num; i++){
arr.push(i);
}
return arr.reduce(function(a,b){
return a*b
},1)
@mmloveaa
mmloveaa / 4-2 Black Jack
Last active April 3, 2016 20:17
4-2 Black Jack
Complete the given function scoreHand so that it determines the score of a hand of Blackjack (aka 21).
This function takes one parameter which is an array of strings that represent each card in the hand. Each card will be one of the following strings: "2", ... ,"10", "J", "Q", "K", "A"
In Blackjack, number cards count as their face value (2 through 10). Jack, Queen and King count as 10. An Ace can be counted as either 1 or 11.
The function should return a number which is the score of the hand.
Important: It is possible for a hand to have multiple possible scores (i.e. with one or more aces). If possible, return the highest score that is less than or equal to 21. Otherwise, return the smallest possible score.
@mmloveaa
mmloveaa / 3 different solutions
Created April 1, 2016 17:26
3 different solutions
// function deepArraySum(array) {
// return array.reduce(function(sum, item) {
// if(typeof item === 'number') {
// return sum + item;
// } else {
// return sum + deepArraySum(item);
// }
// },0);
// }
@mmloveaa
mmloveaa / 4-1 DeepArraySum
Last active April 3, 2016 07:04
4-1 DeepArraySum
Complete the given function deepArraySum that will add all of the numbers in a deeply nested array. The array may be nested arbitrarily deep, and may have numbers at any depth. The function should return the sum of all numbers found at any depth.
All arrays will contain either integer numbers, arrays, or nothing.
If an array is empty or it doesn't contain any numbers, it should have a sum of zero.
Input Format:
The function will have one function
array - an arbitrarily nested array.
@mmloveaa
mmloveaa / 3-31
Last active April 3, 2016 07:03
3-31
Zigzag Array
A group of friends, who shall remain nameless, have hacked into the logistics system of an evil dictator. They want to deplete the dictator's fuel supply by making his army units travel as much distance as possible when they go to suppress rebellions in various locations up and down the coast. While these friends are good at cracking security, they need some help with elementary computing tasks. So they reach out to you. They want to be able to give you an array of positive and negative integers, representing distances north or south of the capital, and they want to see the elements of the array in zigzag order. This means that the largest member appears first, the smallest appears second, and the remaining elements alternate between the larger members decreasing from the largest, and the smaller members increasing from the smallest.
For example, the array [1, 3, 6, 9, -3] becomes [9, -3, 6, 1, 3] in zigzag order.
Specifically, your job is to complete the blank function zigzagArray to accomplis
@mmloveaa
mmloveaa / Missing Word
Last active November 1, 2023 09:52
Missing Word
Julia and Samantha are playing with strings. Julia has a string S, and Samantha has a string T which is a subsequence of string S. They are trying to find out what words are missing in T.
Help Julia and Samantha to solve the problem. List all the missing words in T, such that inserting them at the appropriate positions in T, in the same order, results in the string S.
Constraints
1 <= |T| <= |S| <= 106, where |X| denotes the length of string X.
The length of each word will be less than 15.
Function Parameter
You are given a function missingWords that takes the strings S and T as its arguments.