Manipulate data of arraies to meet the requirements. 8 requirements in total.
- Filter the list of inventors for those who were born in the 1500's.
- Give us an array of the inventors' first and last names.
- Sort the inventors by birthdate, oldest to youngest.
- How many years did all the inventors live?
- Sort the inventors by years lived.
- Create a list of Boulevards in Paris that contain 'de' anywhere in the name. (Data source: Wiki: Boulevards in Paris)
- Sort the people alphabetically by last name. (Sort exercise)
- Sum up the instances of each of these. (Reduce exercise)
JS
- Arrow function
=>
- If
input => input.value > 0
- Means
function (input) { return input.value > 0; }
this
works differently in arrow functions. Its value can't be changed and so it won't be changed by any function likecall()
,apply()
, andbind()
.- Reading: Sitepoint - ES6 Arrow Functions: The New Fat & Concise Syntax in JavaScript
- If
- Method chaining
- e.g.
data.map( ... ).sort( ... ).filter( ... )
- Return
this
in the mdethods to make it easier to read and maintain. - Reading: Gregory Schier - Method Chaining in JavaScript
- e.g.
- Functions
Console.table( data )
- Display tabular data as a table in the console.
Array.prototype.filter( callback )
- Filter a data set
- Return new array.
Array.prototype.map( callback )
- Modify elements' value.
- Return new array.
Array.prototype.sort( callback )
- Sorts the elements of an array by string Unicode or customize function.
- Modify the order of the array, and also return it. (order changed)
Array.prototype.slice( callback )
- Make a shallow copy from the original array.
- Can be used to clone an array.
arr.slice(0)
- Return new sliced array.
Array.prototype.reduce( callback[, initialValue])
- Accumulate each value of the array.
- Return the sum up value from the array.
String.prototype.includes( searchString[, position] )
- Determines whether one string may be found within another string.
- 'position': where begin to search. (optional)
- Return
true
orfalse
.
String.prototype.search( regexp )
- Execute a search for a match between a regular expression and this String object.
- Return a Number: Index of the first match. If not found, return -1.
String.prototype.match( regexp )
- Retrieves the matches when matching a string against a regular expression.
- Return an Array: Containing all the matched substrings. If not found, return a array with a "" element. Detail information:
- array elements:
arr[0]
, whole match & partial matches. - index:
arr.index
, the zero-based index of the whole match. - input:
arr.input
, the original string that was parsed.
- array elements: