This file contains 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
// Problem 1 | |
// console.log(this); | |
// this is: window object or global scope | |
// because... this is in the global scope | |
// // Problem 2 | |
var obj1 = { | |
myName: 'obj1', | |
this: this | |
}; |
This file contains 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
function subArray(array, length) { | |
// get an array | |
// for each over the array | |
// if the index is length spots in | |
// the numbers it traversed should be kept in an | |
// new array | |
let storage = []; | |
let i = 0; | |
// | |
while (storage.length < (array.length / length)) { |
This file contains 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
// function to confirm the ending of a string | |
function confirmEnding(s, eS) { | |
// look at the end string (s) | |
// look at the end of the end string (eS) | |
// compare the index of the last of both | |
// cycle over the two string simulteanously | |
// if gets to the beginning of endString and nothing has been false | |
// return true | |
let splitString = s.split(''); |
This file contains 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
function rot13(S) { | |
//create our alphabet | |
let az = 'abcdefghijklmnopqrstuvwxyz'.toUpperCase().split(''); | |
//create an array for the string passed in | |
let splitS = S.split(' '); | |
//recreate the new arrays | |
let newString = splitS.map((word) => { | |
let splitWord = word.split(''); | |
let newWord = splitWord.map((letter) => { | |
// when letter = az |
This file contains 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
function diff(arr1, arr2) { | |
// put the arrays together | |
// loop over the data | |
combinedArr = arr1.concat(arr2); | |
// filter over the combined array and compare the index and last index of each number | |
// if they match then return that number | |
let combedArray = combinedArr.filter((num) => { | |
if (combinedArr.indexOf(num) === combinedArr.lastIndexOf(num)) { | |
return num; | |
} |
This file contains 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 waffles = [ | |
{ name: 'Chocolate Chip', calories: 800 }, | |
{ name: 'Blueberry', calories: 400 }, | |
{ name: 'Whole Grain', calories: 350 }, | |
{ name: 'Savory', calories: 600 } | |
]; | |
const isHealthy = waffle => waffle.calories < 200; | |
const getName = waffle => waffle.name; | |
const getItemNames = items => items.filter(isHealthy).map(getName); |
This file contains 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
function checkIfArray(arr) { | |
if (arr.constructor === Array ) { | |
return arr; | |
} else return convertToArray(arr); | |
} | |
function convertToArray(string) { | |
return Array.from(string); | |
} |
This file contains 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
function isValidWalk(walk) { | |
let compass = {}; | |
walk.forEach((direction, i) => { | |
if (compass[direction]) { | |
compass[direction] += 1; | |
} else { | |
compass[direction] = 1; | |
} | |
}); |
This file contains 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
function combineValues(data) { | |
// compute the value of the last 3 vals | |
return getLastThree(data).reduce((a, b) => { | |
return a + b; | |
}, 0); | |
} | |
function getLastThree(data) { | |
// if the length is 3 we don't need to pull any specific locations as we are computing against all of these | |
if (data.length > 3) { |
OlderNewer