Chuyển đến nội dung chính

freecodecamp: Functional Programming

freecodecamp: Functional Programming, Learn About Functional Programming

note code to remember about this course

Learn About Functional Programming


"const tea4TeamFCC = getTea(40); // :("

Understand Functional Programming Terminology


"const tea4GreenTeamFCC = getTea(prepareGreenTea,27); // :(
const tea4BlackTeamFCC = getTea(prepareBlackTea,13); // :("

Understand the Hazards of Using Imperative Code


""

Avoid Mutations and Side Effects Using Functional Programming

" return fixedValue+1;"

Pass Arguments to Avoid External Dependence in a Function


"function incrementer (v) {
return v+1
// Add your code above this line
}
"

Refactor Global Variables Out of Functions

"// Add your code below this line
function add (a,bookName) {
let t=a.slice(0);
t.push(bookName);
return t;
// Add your code above this line
}

/* This function should remove a book from the list and return the list */
// New parameters should come before the bookName one

// Add your code below this line
function remove (a,bookName) {
let t=a.slice(0);
let n=t.indexOf(bookName);
if (n >= 0) {
t.splice(n, 1);
return t;
// Add your code above this line
}
}"

Use the map Method to Extract Data from an Array


"

// Add your code below this line

var rating = [];

rating= watchList.map((v)=>{
let obj = {'title':'','rating':0};
obj.title=v.Title;
obj.rating= v.imdbRating;
return obj;
});
// Add your code above this line"

Implement map on a Prototype


" var newArray = [];
// Add your code below this line
for(let i=0;i<this.length;i++){
newArray.push(callback(this[i]));

}
// Add your code above this line
return newArray;"

Use the filter Method to Extract Data from an Array

"// Add your code below this line
function isAdd(){
watchList.hasOwnProperty('Title') && watchList.hasOwnProperty('imdbRating');
return obj
}
var filteredList=watchList.filter((v)=>v.hasOwnProperty('Title') && v.imdbRating>=8.0).map(l=>{
let obj={'title':'','rating':0};
obj.title=l.Title;
obj.rating=l.imdbRating;
return obj;
});
// Add your code above this line"

Implement the filter Method on a Prototype

" // Add your code below this line
this.forEach(function(item){
if(callback(item))
newArray.push(item);
});
// Add your code above this line"

Return Part of an Array Using the slice Method

"return anim.slice(beginSlice,endSlice);"

Remove Elements from an Array Using slice Instead of splice

"// Add your code below this line
if(cities.length>=3)
return cities.slice(0,3);
// Add your code above this line"

Combine Two Arrays Using the concat Method

" // Add your code below this line
return original.concat(attach);
// Add your code above this line"

Add Elements to the End of an Array Using concat Instead of push

"return original.concat(newItem);"

Use the reduce Method to Analyze Data

"var averageRating=watchList.filter(v=>v.Director==='Christopher Nolan').map(v=>{return parseFloat(v.imdbRating)}).reduce((a,c,n,arr)=>a+ c/arr.length,0);"

Sort an Array Alphabetically using the sort Method

" // Add your code below this line
return arr.sort((a,b)=>a>b);
// Add your code above this line"

Return a Sorted Array Without Changing the Original Array

" // Add your code below this line
let tt= arr.slice(0);
let t=[];
return t.concat(tt.sort((a,b)=>a>b));
// Add your code above this line"

Split a String into an Array Using the split Method

"let reg=/\W/;
return str.split(reg);"

Combine an Array into a String Using the join Method

" // Add your code below this line
let reg=/\W/;
let t=str.split(reg);
return t.join(' ');
// Add your code above this line"

Apply Functional Programming to Convert Strings to URL Slugs

"return title.trim().toLowerCase().split(/\W+/).join("-"); "

Use the every Method to Check that Every Element in an Array Meets a Criteria

"return arr.every(function(v){return v>0;});"

Use the some Method to Check that Any Elements in an Array Meet a Criteria

"return arr.some(function(v){return v>0;});"

Introduction to Currying and Partial Application

" // Add your code below this line
return function(y){
return function(z){
return y+z+x;
}
}"



Nhận xét

Bài đăng phổ biến từ blog này

freecodecamp: React

freecodecamp: React step by step to practice Create a Simple JSX Element " const JSX = <h1>Hello JSX!</h1>; " Create a Complex JSX Element " const JSX=<div> <h1></h1> <p></p> <ul> <li></li> <li></li> <li></li> </ul> </div>; " Add Comments in JSX " const JSX = ( /* here in first time */ <div> <h1>This is a block of JSX</h1> <p>Here 's a subtitle</p> </div> ); " Render HTML Elements to the DOM " const JSX = ( <div id= 'challenge-node' > <h1>Hello World</h1> <p>Lets render this to the DOM</p> </div> ); // change code below this line ReactDOM.render(JSX,document.getElementById( 'challenge-node' )); " Define an HTML Class in JSX " cons...

freecodecamp: javascript debugging

freecodecamp: javascript debugging I note that passed code to help coder find the solution Use the JavaScript Console to Check the Value of a Variable "console.log(a);" Understanding the Differences between the freeCodeCamp and Browser Console " console.log(outputTwo); console.clear(); console.log(outputOne); " Use typeof to Check the Type of a Variable " console.log( typeof (seven)); console.log( typeof (three)); " Catch Misspelled Variable and Function Names "" //copy &past variable Catch Unclosed Parentheses, Brackets, Braces and Quotes " let myArray = [ 1 , 2 , 3 ]; let arraySum = myArray.reduce((previous, current) => previous + current); " Catch Mixed Usage of Single and Double Quotes " let innerHtml = "<p>Click here to <a href=\"#Home\">return home</a></p>" ; " Catch Use of Assignment Operator Instead of Equality Ope...

freecodecamp: regular expression

freecodecamp: regular expression How to pass these challenge? I note that snippet code. Help people to help myself. Regular Expressions - Reuse Patterns Using Capture Groups " let reRegex = /^(\d+)\s\1\s\1$/; // Change this line " Use Capture Groups to Search and Replace " let fixRegex = /good/; // Change this line let replaceText = "okey-dokey" ; // Change this line " Remove Whitespace from Start and End " let wsRegex = /\s{2,}/g; // Change this line let result = hello.replace(wsRegex, '' ); // Change this line "