One Paragraph of project description goes here
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
// Bad | |
const nums = [1, 2, 3, 4, 5]; | |
let doubledNums = []; | |
for (let i = 0; i < nums.length; i++) { | |
doubledNums.push(nums[i] * 2); | |
} | |
/* | |
==== Levels of Abstraction ==== | |
- show latest tweet | |
- get latest tweet | |
- make API request for all tweets and convert to JSON | |
- pluck the latest tweet | |
- send response | |
- update database |
// Bad | |
function showLatestTweet() { | |
const latestTweet = fetch('http://api.twitter.com/tweets/123') | |
.then((response) => response.json()) | |
.then((tweetsJson) => tweetsJson.tweets[0]) | |
.catch((err) => { | |
console.error('Error retrieving tweets. Please try again'); | |
}); | |
// Bad | |
const salary = 80000 * (1 - (0.20 + 0.10)); | |
const signingBonus = 1000 * (1 - (0.20 + 0.10)); | |
const yearlyBonus = salary * (1 - (0.20 + 0.10)); | |
// Good |
// Bad | |
const salary = 80000 * 0.20; | |
const signingBonus = 1000 * 0.20; | |
const yearlyBonus = salary * 0.05 * 0.20; | |
// Good |
const addTo = (cache) => (num) => { | |
cache[num] = true; | |
} | |
const smallestPositive = (nums) => { | |
let cache = []; | |
nums.forEach(addTo(cache)); | |
for (let i = 1; i < cache.length; i++) { |
const peek = (stack) => stack[stack.length - 1]; | |
const isValidParentheses = (str) => { | |
const stack = []; | |
const closingPairs = { | |
']': '[', | |
'}': '{', | |
')': '(' | |
} |
const recursiveFactorial = (n) => n === 1 ? 1 : n * recursiveFactorial(n - 1); | |
const iterativeFactorial = (n) => { | |
let result = 1; | |
for (let i = 2; i <= n; i++) { | |
result *= i; | |
} | |
return result; |
const reduceString = (str, targetChar) => { | |
for (let i = str.length - 1; i >= 0; i--) { | |
if (str[i] !== targetChar) continue; | |
i--; | |
while (str[i] === targetChar) { | |
str = str.slice(0, i) + str.slice(i + 1); | |
i--; | |
} |