forked from AustinCodingAcademy/javascript-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
separated exercises.js onto its own branch #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aaronaltounian
wants to merge
1
commit into
gh-pages
Choose a base branch
from
class-5-exercises
base: gh-pages
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| 'use strict' | ||
|
|
||
| // 1. Create array 'cars' with 4 different types of cars & console.log: | ||
| let cars = ['Ford', 'Lotus', 'Renault', 'Peugeot']; | ||
| console.log(cars); | ||
|
|
||
| //2. Create array 'morecars' with 4 more types of cars and concat with cars: | ||
| let moreCars = ['Pagani', 'Porsche', 'Audi', 'Honda']; | ||
| let totalCars = cars.concat(moreCars); | ||
|
|
||
| //3. console.log the indexOf 'Honda' and lastIndexOf 'Ford': | ||
| console.log(totalCars.indexOf('Honda')); | ||
| console.log(totalCars.lastIndexOf('Ford')); | ||
|
|
||
| //4. Use join method to convert the array totalCars to a string: | ||
| let stringOfCars = totalCars.join(' '); | ||
| console.log(stringOfCars); | ||
|
|
||
| //5. Use split method to convert stringOfCars back to an array: | ||
| totalCars = stringOfCars.split(' '); | ||
|
|
||
| //6. Use reverse method to create an array carsInReverse from totalCars: | ||
| let carsInReverse = totalCars.reverse(); | ||
|
|
||
| //7: Use sort method to put carsInReverse in alphabetical order: | ||
| carsInReverse.sort(); | ||
| // prediction: 'Audi' is in index 0: | ||
| console.log(carsInReverse.indexOf('Audi')); | ||
|
|
||
| //8. Use slice method to remove Ford and Honda from carsInReverse, | ||
| // and move them into a new array removedCars: | ||
| let removedCars = carsInReverse.slice(1, 3); | ||
| console.log(removedCars); | ||
|
|
||
| //9. Use splice method to remove 2nd and 3rd items in carsInReverse & replace them with 'Ford' and 'Honda' (which is weird because the 2nd and 3rd items are already Ford and Honda...): | ||
| carsInReverse.splice(1, 2, 'Ford', 'Honda'); | ||
| console.log(carsInReverse); | ||
|
|
||
| //10. Use push method to add the types of cars removed using splice method to carsInReverse: | ||
| carsInReverse.push('Ford', 'Honda'); | ||
| console.log(carsInReverse); | ||
|
|
||
| //11. Use pop method to remove and console.log the last item in carsInReverse: | ||
| console.log(carsInReverse.pop()); | ||
|
|
||
| //12. Use shift method to remove and console.log the first item in carsInReverse: | ||
| console.log(carsInReverse.shift()); | ||
|
|
||
| //13. Use the unshift method to add a new type of car to the beginning of carsInReverse: | ||
| carsInReverse.unshift('Volkswagen'); | ||
| console.log(carsInReverse); | ||
|
|
||
| //14. Create an array called numbers with the following items: 23, 45, 0, 2, write code that will add 2 to each item in the array numbers. | ||
| let numbers = [ 23, 45, 0, 2 ]; | ||
| for(let x in numbers){ | ||
| numbers[x] += 2; | ||
| console.log(numbers[x]); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the ES6 version of this!