Skip to content

Instantly share code, notes, and snippets.

@mmloveaa
mmloveaa / aogprotips.txt
Last active April 2, 2020 01:32
<AoGProTips> Synchronize animations with the Text-To-Speech
const callbacks = {
onTtsMark(markName) {
if (markName === ’START_ROAR’) {
beginRoaring();
} else if (markName === ’STOP_ROAR’) {
stopRoaring();
} else {
...
}
}
@mmloveaa
mmloveaa / 4-27 Seek and Destroy
Last active December 29, 2017 09:30
5/3 Seek and Destroy
You will be provided with an initial array (the first argument in the destroyer function),
followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
function destroyer(arr) {
var myArguments = [];
for (var i=1; i<arguments.length; i++){
myArguments.push(arguments[i]);
}
return arr.filter(function(remove){
return myArguments.indexOf(remove) < 0;
@mmloveaa
mmloveaa / 4-26 Free Code Camp remove all falsy
Last active July 8, 2018 13:00
4-26 Free Code Camp remove all falsy
Remove all falsy values from an array.
Falsy values in JavaScript are false, null, 0, "", undefined, and NaN.
Remember to use Read-Search-Ask if you get stuck. Write your own code.
Here are some helpful links:
Boolean Objects
Array.filter()
@mmloveaa
mmloveaa / 4-19 Q2 Calculate Factorial
Last active December 29, 2017 09:31
4-19 Q2 Calculate Factorial
Write a program that will read an integer N from STDIN and compute the factorial of N. The input to your program will contain many lines. On each line there will be exactly one integer. Your program should print the factorial of each integer in a separate line. Your program should terminate when it reads a number that is not positive.
1 <= N <= 15
Sample Input
1
2
3
-1
Sample Output
@mmloveaa
mmloveaa / 4-23 Valid Flag solution
Created April 23, 2016 21:05
4-23 Valid Flag solution
if(validRow(arrayOfFlagObjects[0].flag)===true && validNeighbors(arrayOfFlagObjects[0].flag)===true){
console.log("YES");
}else {
console.log("NO");
}
// Solution 1
process.stdin.resume();
@mmloveaa
mmloveaa / 4-19 -Q4 Sherlock and The Beast
Last active April 25, 2016 05:03
4-19 -Q4 Sherlock and The Beast
Sherlock Holmes and his dear friend Dr. Watson are working on an urgent problem. Watson had earlier learned through his "special relationship" contacts at MI6 that that the CIA has lately been facing weird problems with their supercomputer, 'The Beast'. Then, Sherlock received a note from Professor Moriarty, his archenemy, boasting that he has infected 'The Beast' with a virus.
Now, all of Sherlock's past efforts to subdue Moriarty had been in vain, but the note gave him new hope to finally triumph over his nemesis. You see, the note had been written on a piece of paper previously sat on Moriaty's desk under another piece of paper. Unbeknownst to anyone but the intrepid Sherlock Holmes, it had an impression of a number N on it. After following up with more clues from his past experience with Moriarty, Sherlock figured out that the key to remove the virus is the largest 'Decent' Number having N digits.
A 'Decent' Number has -
Only 3 and 5 as its digits.
The number of times 3 appears is divisible by 5.
The nu
@mmloveaa
mmloveaa / 4-19 Q5 - Closest Num
Last active December 29, 2017 09:33
4-19 Q5 - Closest Num
Sorting is useful as a first step in many different operations. For example, searching for a specific elements is easier on a sorted data structure. But search is not the only task facilitated by an initial sort.
Given a list of unsorted numbers A={ a1, a2, a3,.. ,aN}, can you find the pair of numbers that has the smallest absolute difference between its elements? If there are multiple pairs that have the same absolute distance as the minimum, find them all.
Constraints
1 ≤ N ≤ 2x105
-107 ≤ x ≤ 107, where x ∈ array
No repetitions: ai≠ aj where 1 ≤ i < j ≤N
Input Format
@mmloveaa
mmloveaa / 4-19 - Q6 Modify Price
Last active August 23, 2020 10:11
4-19 - Q6 Modify Price
Michael is a shop owner who keeps n list, L, of the name and sale price for each item in inventory. The store employees record the name and sale price of every item sold. Michael suspects his manager, Alex, of embezzling money and modifying the sale prices of some of the items. Write a program that finds the number of times Alex recorded an incorrect sale price.
Complete the verifyItems function provided in your editor so that it returns the number of incorrect sale prices recorded by Alex. It has 4 parameters:
origItems: An array of strings, where each element is an item name.
origPrices: An array of floating point numbers, where each element contains the original (correct) price of the item in the corresponding index of origItems.
items: An array of strings containing the name of the items with sales recorded by Alex.
prices: An array of floating point numbers, where each element contains the sale price recorded by Alex for the item in the corresponding index of items.
Note: Where required by the langua
@mmloveaa
mmloveaa / 4-19 Fib Q1
Last active December 29, 2017 09:29
4-19 Q1
Complete the function fibonacci to return an array containing the first N Fibonacci numbers.
fib(n) = n , n <= 1
= fib(n-2) + fib(n-1), otherwise
Constraints:
1 ≤ N ≤ 10
Sample Input
4
@mmloveaa
mmloveaa / 4-11 Patrick's solution
Created April 11, 2016 17:01
4-11 Patrick's solution
// var assert = require('assert');
var assert = require('chai').assert;
describe('The findMaxProfit function', function() {
function findMaxProfit(stockPrices) {
// make sure we have at least 2 prices
if (stockPrices.length < 2) {
throw new Error('Getting a profit requires at least 2 prices');