Option #1

JavaScript Filter Function: fiter()

https://blog.codeanalogies.com/2018/05/14/javascripts-filter-function-explained-by-applying-to-college/

You input an array, and you filter out the elements that fulfill a specific condition into a new array.

Filter is an array method which is like a list of whatever you are tying to figure out and stats for each item on list ex. Hockey players/ stats.

This method uses a callback function that runs on each element in the array. This means after coding out the program and running it the code ex.

let students = [ { name: "david", GPA: 3.3 },

This part of the code uses the stats added previously and puts them into categorical lists. There could be many different combinations of these lists ex. name (alphabetical), stat 1, stat 2, etc., and reversed of each.

Then uses a return statement to figure out which item is or is not in the parameters asked for in the example code lines. A statistics worker would most benefit.

] let admitted = students.filter(function(student){ return student.gpa > 3.2;})
];*/

This function is a simpler version of Loop()

Two Conditions:

Similar to the previous condition of 1 but with extra stats to add to them. The input in the Callback Function is written the same.

The only difference is the Return Statement has 2 conditions.

let admitted = students.filter(function(student){ let goodStudent = student.gpa > 3.2 && student.sat > 1900 return goodStudent; })

This method can be used for more conditions. It is good for a large number of inputted data and an easier organizer of said data to get from the Return Statement.

For more videos from Code Analogies

https://www.codeanalogies.com/

Advertisements
Create your website at WordPress.com
Get started
%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close