Skip to content

Instantly share code, notes, and snippets.

View ambergkim's full-sized avatar

Amber Kim ambergkim

View GitHub Profile
@ambergkim
ambergkim / FCCBonfire.js
Created November 18, 2015 21:51
Free Code Camp Bonfire: Mutations
function mutation(arr) {
firstWord = arr[0].toLowerCase();
secondWord = arr[1].toLowerCase().slice('');
lettersFound = 0;
for(i=0; i<secondWord.length; i++){
indexSearch = secondWord[i];
indexSearchResult = firstWord.indexOf(indexSearch, 0);
if(indexSearchResult == -1) {
return false;
} else {
@ambergkim
ambergkim / FCCBonfireFalsyBouncer.js
Created November 19, 2015 00:53
Free Code Camp Bonfire: Falsy Bouncer
function bouncer(arr) {
filteredArr = arr.filter(Boolean);
return filteredArr;
}
bouncer([7, "ate", "", false, 9]);
@ambergkim
ambergkim / callback-vs-promises.js
Last active July 4, 2018 01:38
JavaScript Callbacks vs Promises
// *******************
// callback version
// *******************
function getDataCallback(data) {
// do something with the new data data
}
function getData(callback) {
// getting the data
@ambergkim
ambergkim / convert-int-roman.js
Last active July 11, 2018 19:28
Converting Integers to Roman Numerals
// Roman Numerals
// I, II, III, IV, V, VI, VII, VIII, IX, X
// X, XX, XX, XL, L, LX, LXX, LXXX, XC, C
// C, CC, CCC, CD, D, DC, DCC, DCCC, CM, M
// EXAMPLES:
// 2018: MM X VIII
// 199: C XC IX
// Input: Integer
@ambergkim
ambergkim / division-from-scratch.js
Created July 14, 2018 00:49
Create a function to divide integers w/o using javascript division.
// Inputs: int, divideByInt
// Output: Int
// Sets
// Current Set
// Loop through int
// if current < divide
// current ++
@ambergkim
ambergkim / palindrome.js
Created July 14, 2018 00:55
check if a string is a palindrome
// Input: str
// Output: true or false
// Example: madam -> 5 length, odd
// Example: wowwow -> 6 length, even
// Example: hello -> fail, odd
// Example: hi -> fail, even
// isPalindrome(str)
// midpoint str/2 ceil -1
@ambergkim
ambergkim / division-from-scratch-v2.js
Created July 14, 2018 01:05
JavaScript division with division operator
// Input: int, divInt
// Output: int
// helper
// return whole sets & remainder
// input: int, divInt
// output: [sets, remainder]
// main
// fin str
@ambergkim
ambergkim / find-duplicates.js
Created July 14, 2018 01:12
takes in 2 arrays. find what is the same for both.
// only list duplicates once
// return array of duplicates
// helper findInstances(array)
// obj
// loop through array
// if no key in obj, create key
// return obj
// main findSimilar(arr1, arr2)
// O(N)
function remDupes(arr) {
// have we seen this?
let hash = [];
// pointer 1
p = -1;
// establish i as pointer 2