diff --git a/advancedArrayMethods.js b/advancedArrayMethods.js new file mode 100644 index 0000000..e69de29 diff --git a/advancedArraysAndObjects.js b/advancedArraysAndObjects.js new file mode 100644 index 0000000..30e3d52 --- /dev/null +++ b/advancedArraysAndObjects.js @@ -0,0 +1,249 @@ +const letterCounter = (phrase) => { + + counter = 0 + //return phrase.length + // for (letter in phrase) + // { + // if (phrase.slice(letter-1, letter) != ' ') + // { + // counter ++ + // } + // } + for (letter of phrase) + { + + if (letter != ' ') + { + counter ++ + } else { + phrase = String(phrase).replace(' ','-') + counter ++ + } + } + return counter +} + +const countTheLetters = (phrase) => { + result = 0 + for (const letter in phrase){ + console.log(Number(letter)+1) + result = Number(letter)+1 + } + + return {result} +} + +const sumOfArrays =(numbers) => { + let result = 0; + + for (const number of numbers){ + result += number + } + return {total:result} + +} + +const maxInArray = (numbers) => { + let result = numbers[0]; + + for (const number of numbers){ + if (result < number) { + result = number; + } + } + + return {HighestNumberInArray:result} +} + +const frequencyInArray = (anArray, searchValue) => { + + let count = 0; + + for (const value of anArray){ + if (value == searchValue) { + count ++; + } + } + return {Frequencyof: count} + + +} + + +const frequencyInString = (string) => { + + results = []; + for (const letter of string){ + let countOfCharacter = String(string).split(letter).length -1 ; + if(!doesItExistIntheArrary(letter, results)){ + results.push(newLetterCountObject(letter, countOfCharacter)) + } + } + return results; +} + +const doesItExistIntheArrary = (letter, anArray) =>{ + + let doesItExist = false; + if ( anArray.length > 0 ){ + for( const letterCounter of anArray){ + if ( letterCounter.letter == letter){ + doesItExist = true; + } + + } + } + return doesItExist; +} + + +const newLetterCountObject = (letter, increaseCountBy) => { + + + const letterCounter = { + + letter:letter, + count:increaseCountBy + } + + return letterCounter; +} + +const frequencyInString2 = (string) => { + + //make frequency object + let frequency = {}; + + for (const letter of string){ + + if (letter in frequency) + { + frequency[letter] += 1 + + } else { + frequency [letter] = 1 + } + } + + return frequency; +} + +const wordFrequency1 = (string) => { + + let frequency = {}; + + let theWord = '' + for (const letter of string){ + + + if (letter == ' ') + { + if (theWord in frequency) + { + frequency[theWord] ++; + } else { + frequency[theWord] = 1; + } + theWord = ''; + + + } else { + theWord += letter; + + } + } + + + if (theWord in frequency) + { + frequency[theWord] ++; + } else { + frequency[theWord] = 1; + } + + return frequency; +} + +//this time create a word array like the tutorial +const wordFrequency2 = (string) => { + +// let wordArray = buildWordArray(string); + let wordArray = string.split(' '); + let frequency = {}; + + + for (word of wordArray) + { + if (word in frequency) + { + frequency[word] ++; + } else { + frequency[word] = 1; + } + + } + return frequency; +} + +//while this works, and was shown in the tutorial, it is by chance. It would be a +//bad idea to just reuse a function like that because it was not actually meant to +// do this with an array. +// that said, it might make sense to "rebrand" the function to do this more explicitly +const wordFrequency3 = (string) => { + + // let wordArray = buildWordArray(string); + let wordArray = string.split(' '); + + return frequencyInString2(wordArray); + + } +//implimented my own split by ' ' because I didn't know that split did that lol +const buildWordArray = (string) => { + + let wordArray = []; + theWord = ''; + + for (const letter of string) { + + if (letter == ' ') + { + wordArray.push(theWord) + theWord = ''; + + } else { + theWord += letter; + } + } + wordArray.push(theWord) + theWord = ''; + + return wordArray; +} + +let theNumbers = [1,2,3,4,5,6, 7.9,2,3,4,5,6, 7.9,2,3,4,5,6, 7.9,2,3,4,5,6, 7.9,2,3,4,5,6, 7.9,2,3,4,5,6, 7.9,2,3,4,5,6, 7.9,2,3,4,5,6, 7.9,2,3,4,5,6, 7.9,2,3,4,5,6, 7.9] +let theOtherNumbers = [2,12,5,16,10,12,5,16,10,12,5,16,10,12,5,16,10,12,5,16,10,12,5,16,10,12,5,16,10,12,5,16,10,12,5,16,10,12,5,16,10,12,5,16,10,12,5,16,10,12,5,16,10] +let theStrings = ['testtesttesttest', 'test', 'not a test', 'pew pew','test', 'test', 'not a test', 'pew pew','test', 'test', 'not a test', 'pew pew','test', 'test', 'not a test', 'pew pew'] +let aString = 'aaa bbb ccc dd eeeee f ggggggggg h zzzz aa bbbb cccc aaa aaa aaa bbbbbbbbb bbb'; +let bString = ' test test test a jason jason two two three three three four four four four' +// let arrayOfArrays =[theNumbers,theOtherNumbers]; +// randomString = "this is a test " +// anotherRandomString = "this is a test or is it" + +// console.log(letterCounter(randomString)) +// console.log(countTheLetters(anotherRandomString)) +// console.log(randomString) + +// console.log(sumOfArrays(theNumbers)) +// console.log(sumOfArrays(theOtherNumbers)) + +// console.log(maxInArray(theNumbers)) +// console.log(maxInArray(theOtherNumbers)) + +// console.log(frequencyInArray(theNumbers,1)) +// console.log(frequencyInArray(theOtherNumbers, 12)) +// console.log(frequencyInString(aString) ) +// console.log(frequencyInString2(aString) ) +//console.log(aWordFrequency(aString) ) +console.log(wordFrequency1(bString) ) +console.log(wordFrequency2(bString) ) +console.log(wordFrequency3(bString) ) \ No newline at end of file diff --git a/babyWeatherApp.js b/babyWeatherApp.js new file mode 100644 index 0000000..e06792e --- /dev/null +++ b/babyWeatherApp.js @@ -0,0 +1,17 @@ +//Baby weather app + + +let isRaining = prompt('Is it raining? (Y/N)'); + +if ( isRaining == 'y' || isRaining == 'Y' || isRaining == 'n' || isRaining == 'N') +{ + if(isRaining == 'y' || isRaining =='Y') + { + console.log("grab your umbrella") + } else { + console.log("Wear your Sunglasses") + } +} else { + console.error('invalid input" "' + isRaining+'" ') + // isRaining = prompt('Is it raining? (Y/N)'); +} \ No newline at end of file diff --git a/basicsOfArrays.js b/basicsOfArrays.js new file mode 100644 index 0000000..47a59cf --- /dev/null +++ b/basicsOfArrays.js @@ -0,0 +1,12 @@ + + +let groceries = ['apple', 'pear', 'steak']; + +groceries.push('bread','cheese', 'flour', 'butter'); +groceries.push('hamburger','hotdog', 'salad', 'blueberries'); +//console.log (groceries[6]); + + +console.log (groceries.slice(3,6)); +console.log (groceries.length) +console.log (groceries.indexOf('bread')) \ No newline at end of file diff --git a/basicsOfForLoops.js b/basicsOfForLoops.js new file mode 100644 index 0000000..6a4b8e7 --- /dev/null +++ b/basicsOfForLoops.js @@ -0,0 +1,63 @@ + + +let groceries = ['apple', 'pear', 'steak']; +groceries.push('bread','cheese', 'flour', 'butter'); +groceries.push('hamburger','hotdog', 'salad', 'blueberries'); + +groceries.push('bread','cheese', 'flour', 'butter'); +groceries.push('hamburger','hotdog', 'salad', 'blueberries'); + + + +// for (let i = 0; i < groceries.length; i++) { +// console.log(groceries[i]) +// } + +// for (const food of groceries) +// { +// console.log(food); +// //console.log(''); + +// } + +const removeDuplicatesFromArray = (anArray) => { + +} + +const doubleAnArray = (aNumberArray) => { + + doubledArray = []; + for (const aNumber of aNumberArray){ + doubledArray.push(aNumber*2); + + } + return doubledArray; +} + +const squareAnArray = (aNumberArray) => { + + doubledArray = []; + for (const aNumber of aNumberArray){ + doubledArray.push(aNumber*aNumber); + + } + return doubledArray; +} + +let theNumbers = [1,2,3,4,5,6] +let theOtherNumbers = [2,12,5,16,10] +let doubleTheNumbers = doubleAnArray(theNumbers); + +// for ( aNumber of theNumbers) +// { + +// aNumber = 2*aNumber; +// console.log(aNumber); + +// doubleTheNumbers.push(aNumber); +// //console.log(''); + +// } + + console.log(doubleTheNumbers) + console.log(squareAnArray(theOtherNumbers)) \ No newline at end of file diff --git a/basicsOfObjects.js b/basicsOfObjects.js new file mode 100644 index 0000000..189bce9 --- /dev/null +++ b/basicsOfObjects.js @@ -0,0 +1,134 @@ +// const person = { +// firstName:'Jason', +// lastName: 'Wechsler', +// clothingTop: 'Red Shirt', +// marriedTo: '', +// assets:1200000, +// liabilities:415000, + +// // const netWorth = (assets, liabilities) => +// // { +// // return assets-liabilities +// // } +// netWorth: function(){ +// return this.assets - this.liabilities +// } + +// } + +// const person2 = { +// firstName:'Kelsey', +// lastName: 'Volkert', +// clothingTop: 'Blue Corset', +// marriedTo: person, +// assets:1200000, +// liabilities:450000, + +// // const netWorth = (assets, liabilities) => +// // { +// // return assets-liabilities +// // } +// netWorth: function(){ +// return this.assets - this.liabilities +// } +// } + +//person.marriedTo = person2 + +// console.log('Dot Notation - First Name: '+ person.firstName + ' Last Name: ' + person.lastName + ' Shirt Color: ' + person.shirt) +// console.log('Bracket Notation - First Name: '+ person['firstName'] + ' Last Name: ' + person['lastName'] + ' Shirt Color: ' + person['shirt']) + +//person2.phone = '7755551212' +//person['phone'] = '7025551212' + +// console.log(person.phone) +// console.log(person) +// console.log(person2) + +const makeAnIntroduction = (aPerson) => { + + console.log('Hi my name is ' + aPerson.firstName +' ' + aPerson.lastName ) + if(aPerson.clothingTop !='') { + console.log('I am wearing a ' + aPerson.clothingTop ) + } else { + console.log('I am topless') + } + + if (aPerson.marriedTo.length !=0){ + + //need to add a loop through the array to support polygamy or something + console.log('I am married to ' + aPerson.marriedTo[0].firstName +' ' + + aPerson.marriedTo.lastName) + + if(aPerson.marriedTo.clothingTop != '') + { + console.log('My spouse is wearing a ' + aPerson.marriedTo[0].clothingTop ) + } + } + + if (! isNaN(aPerson.netWorth()) ) + { + console.log('My Networth is $' + aPerson.netWorth()) + } + console.log(''); + +} + +const makeACustomIntroduction = (aPerson) => { + + makeAnIntroduction(aPerson) +} + +const makeACustomPerson = (aFirstName, aLastName, aClothingTop, assets, liabilities, phone) => { + const customPerson = { + firstName: aFirstName, + lastName: aLastName, + clothingTop: aClothingTop, + // randomally to see if I could do it, support polyamorous marriages + marriedTo:[], + assets:assets, + phone:phone, + + liabilities:liabilities, + netWorth: function(){ + return this.assets - this.liabilities + } + + + } + return customPerson; + +} + +const getMarried = (aPerson, anotherPerson) => { + aPerson.marriedTo.push(anotherPerson) + anotherPerson.marriedTo.push(aPerson); + + totalAssets = aPerson.assets + anotherPerson.assets + totalLiabilities = aPerson.liabilities + anotherPerson.liabilities + + aPerson.assets = totalAssets ; + aPerson.liabilities = totalLiabilities; + anotherPerson.assets = totalAssets ; + anotherPerson.liabilities = totalLiabilities; +} + + +jason = makeACustomPerson('Jason', 'Wechsler', 'T-Shirt', 750000, 20000,'555-555-1212') +kelsey = makeACustomPerson('Kelsey', 'Volkert', 'Blue Corset', 250000, 20000,'555-555-1212') + +getMarried(jason,kelsey); + +makeAnIntroduction(jason); +makeAnIntroduction(kelsey); + + + + +janet = makeACustomPerson('Janet', 'Sanderson', 'Black Dress', 10000, 20000,'555-555-1212') +bob = makeACustomPerson('Bob', 'Sanderson', 'Teal Buttom Up', 20000, 40000,'555-555-1313') + +getMarried(janet,bob); + +makeACustomIntroduction(janet); +makeACustomIntroduction(bob); \ No newline at end of file diff --git a/exercises/arraysorting.js b/exercises/arraysorting.js index d40d935..9339caa 100644 --- a/exercises/arraysorting.js +++ b/exercises/arraysorting.js @@ -5,7 +5,7 @@ // Write a function that takes in an array and sort the numbers inside from least to greatest function sortArray (array) { - + Array(array).sort(); } // BONUS sort the array without using .sort() diff --git a/index.html b/index.html index a0d6899..254a1d1 100644 --- a/index.html +++ b/index.html @@ -50,7 +50,8 @@