This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const callbacks = { | |
onTtsMark(markName) { | |
if (markName === ’START_ROAR’) { | |
beginRoaring(); | |
} else if (markName === ’STOP_ROAR’) { | |
stopRoaring(); | |
} else { | |
... | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(validRow(arrayOfFlagObjects[0].flag)===true && validNeighbors(arrayOfFlagObjects[0].flag)===true){ | |
console.log("YES"); | |
}else { | |
console.log("NO"); | |
} | |
// Solution 1 | |
process.stdin.resume(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); |
NewerOlder