Prep
- Look up javascript string methods
- try to use 5 of them with sample content in a js file
- note at least 1 example per method of an application of where it would be useful.
- Try the Javascript array methods tutorial
String Methods
Activity: Code Spike String Methods
A code spike is a short focused study on a technical aspect of a project with the objective of testing whether or not the code/library/approach etc will be viable. This often involves communicating details about the code spike with other members of a team.
You will get to do a mini version of this in your scrum groups where you’ll each spend a bit of time researching some code and demonstrate how to use it to one another.
20 min - Code Learning & Practice
In your scrum groups, Each of you will pick a use case oriented category and explore the string methods associated with it (take a couple minutes to divide them up before you start). choose from the following
- Data Validation and Sanitization:
- Methods: startsWith(), endsWith(), includes(), toLowerCase(), toUpperCase(), trim()
- Text Processing and Manipulation:
- Methods: join(), replace(), substring(), indexOf(), pop(), shift, unshift(), slice(), splice()
- Formatting and Presentation:
- Methods: repeat(), toLowerCase(), toUpperCase(), trim()
- User Input Handling:
- Methods: trim(), toLowerCase(), toUpperCase(), split(), join(), replace().
Take note of a use case for each method and provide a simple demo to your teammates of how to use it.
10 minutes: Mini Demos
Take turns explaining 2 of your methods to each other and what they do. Focus on the differences between them as they will all be similar but with minor variances.
- Explain what you were learning how to do and common use cases
- Demonstrate 2 methods with a simple example
- Discuss a key takeaway that you gained from this code spike.
Array Methods
Key Takeaways
- JS provides powerful methods for editing array elements
.forEach()
,.map()
,.filter()
,.reduce()
,.slice()
,.sort()
,.includes()
are all highly specialized
Activity: Code Spike Array Methods
This is the same as the first activity, however you’ll be looking at array methods this time.
20 min - Code Learning & Practice
Just like before, choose from the following topics:
Take note of a use case for each method and provide a simple demo to your teammates of how to use it.
- Iteration and Manipulation:
- forEach(callbackFunction): Execute a function for each element.
- map(callbackFunction): Create a new array by applying a function to each element.
- filter(callbackFunction): Create a new array with elements that pass a test.
- reduce(callbackFunction, initialValue): Reduce the array to a single value by applying a function.
- Searching and Filtering:
- indexOf(searchElement, fromIndex): Find the first occurrence of an element.
- lastIndexOf(searchElement, fromIndex): Find the last occurrence of an element.
- includes(searchElement, fromIndex): Check if the array contains an element.
- find(callbackFunction): Find the first element that passes a test.
- findIndex(callbackFunction): Find the index of the first element that passes a test.
- Adding, Removing, and Sorting:
- push(element): Add an element to the end of the array.
- pop(): Remove and return the last element from the array.
- shift(): Remove and return the first element from the array.
- unshift(element): Add an element to the beginning of the array.
- sort(compareFunction): Sort the elements of the array in place.
- splice(startIndex, deleteCount, …items): Add/remove elements at a specific index.
- Data Transformation and Aggregation:
- concat(…arrays): Combine multiple arrays into a single array.
- slice(start, end): Extract a part of the array based on index positions.
- join(separator): Join an array of strings into a single string with a separator.
- every(callbackFunction): Check if all elements pass a test.
- flat(depth): Flatten an array of nested arrays to a single level.
10 minutes: Mini Demos
Take turns explaining your methods to each other and what they do. Focus on the differences between them as they will all be similar but with minor variances.
- Explain what you were learning how to do and common use cases
- Demonstrate 2 methods with simple examples
- Discuss a key takeaway that you gained from this code spike.
Today's Achievement
Mini Assignment 3
- Due:: Sunday February 18
- Weight: 5%
- Objective: Solve small control flow challenges