×
Use the following object for this set of questions:
let users = [ { username: 'larry', email: '[email protected]', yearsExperience: 22.1, favoriteLanguages: ['Perl', 'Java', 'C++'], favoriteEditor: 'Vim', hobbies: ['Fishing', 'Sailing', 'Hiking'], hometown: { city: 'San Francisco', state: 'CA' } }, { username: 'jane', email: '[email protected]', yearsExperience: 33.9, favoriteLanguages: ['Haskell', 'Clojure', 'PHP'], favoriteEditor: 'Emacs', hobbies: ['Swimming', 'Biking', 'Hiking'], hometown: { city: 'New York', state: 'NY' } }, { username: 'sam', email: '[email protected]', yearsExperience: 8.2, favoriteLanguages: ['JavaScript', 'Ruby', 'Python', 'Go'], favoriteEditor: 'Atom', hobbies: ['Golf', 'Cooking', 'Archery'], hometown: { city: 'Fargo', state: 'SD' } }, { username: 'anne', email: '[email protected]', yearsExperience: 4, favoriteLanguages: ['C#', 'C++', 'F#'], favoriteEditor: 'Visual Studio Code', hobbies: ['Tennis', 'Biking', 'Archery'], hometown: { city: 'Albany', state: 'NY' } }, { username: 'david', email: '[email protected]', yearsExperience: 12.5, favoriteLanguages: ['JavaScript', 'C#', 'Swift'], favoriteEditor: 'VS Code', hobbies: ['Volunteering', 'Biking', 'Coding'], hometown: { city: 'Los Angeles', state: 'CA' } } ];
printEmails
which console.log's each email for the users.printEmails(); // [email protected] // [email protected] // [email protected] // [email protected] // [email protected]
printHobbies
which console.log's each hobby for each user.printHobbies(); // "Fishing", // "Sailing", // "Hiking", // "Swimming", // "Biking", // "Hiking", // "Golf", // "Cooking", // "Archery", // "Tennis", // "Biking", // "Archery", // "Volunteering", // "Biking", // "Coding",
findHometownByState
which returns the first user which has a hometown of the state that is passed infindHometownByState('CA'); /*/ { username: "larry", email: "[email protected]", years_experience: 22.1, favorite_languages: ["Perl", "Scala", "C++"], favorite_editor: "Vim", hobbies: ["Fishing", "Sailing", "Hiking"], hometown: { city: "San Francisco", state: "CA" } } /*/
allLanguages
which returns an array of all of the unique valuesallLanguages();
// ["Perl", "Scala", "C++","Haskell", "PHP","JavaScript","Ruby", "Python", "Go","C#", "F#", "Swift"]
hasFavoriteEditor
which returns a boolean if any of the users have the editor passed inhasFavoriteEditor('VS Code'); // true hasFavoriteEditor('Eclipse'); // false
findByUsername
which takes in a string and returns an object in the users
array that has that usernamefindByUsername('david'); /*/ { username: "david", email: "[email protected]", years_experience: 12.5, favorite_languages: ["JavaScript", "C#", "Swift"], favorite_editor: "VS Code", hobbies: ["Volunteering", "Biking", "Coding"], hometown: { city: "Los Angeles", state: "CA" } } /*/
vowelCount
that accepts a string and returns an object with each key being the vowel and the value being the number of times the vowel occurs in the string (the order of keys in the object does not matter).vowelCount('incredible'); // {i:2, e: 2} vowelCount('awesome'); // {a:1, e:2, o:1}
removeVowels
that accepts a string and returns an array of each character that is not a vowel (y should not count as a vowel for this function).removeVowels('amazing'); // ["m","z","n","g"] removeVowels('fun'); // ["f","n"] removeVowels('silly'); // ["s","l","l","y"]
Complete the exercises in the Javascript Iterators repository.
For solutions to these exercises, click here.