Filter
by jessekinsman
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.2/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.4/jasmine.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.4/jasmine-html.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.4/jasmine.css">
<link rel="stylesheet" href="https://codepen.io/btholt/pen/WrwzJZ.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.4/boot.js"></script>
<div id='target'>no snapshots</div>
Babel + JSX
/*
Filter!
Test 1
Name your function filterOutOdds
Write a function that takes a list and filters out all the odd numbers
Takes one parameter, a list of numbers
Returns a list with only the even numbers remaining
Test 2
Name your function filterState
Takes two parameters
- a list of people objects that have a name and state (as in state where they're from)
- a string of the state which you want to filter for
Returns a list of people objects (in the same order) from the state specified
Test 3
Name your function showOutOfCADevs
You will need to use map, filter, and reduce (you could skip map by try to use it)
Takes one parameter, a list of people objects (same from test 3)
Takes that list, filters out people from CA, pulls out the name strings and throws
away the rest of the object, uppercases the name of the person, and reduces the
list down to one string, the names separated by a comma and a space (", "). Use
reduce, not join.
Returns a string of uppercase names, separated by a comma and a space.
Test 4
Name your function myFilter
myFilter implements filter
Takes two parameters:
- A list that will be filtered
- A function that returns true if the item stays in the list, or false if it removed
Returns a list that has been filtered
*/
const removeOds = (num) => num % 2 === 0;
const filterOutOdds = (list) => list.filter(removeOds);
const filterState = (list, state) => {
const newList = list.filter(function(person){
return person.state === state;
});
return newList;
}
const removeState = (list, state) => {
const newList = list.filter(function(person){
return person.state !== state;
});
return newList;
}
const titleCase = (str) => str.substr(0,1).toUpperCase() + str.substr(1,str.length);
const modifyName = (obj) => {
let name = obj.name.split(" ");
console.log(name.toString());
return name.reduce(function(acc, item) {
return (acc === '') ? titleCase(item)...