Skip to content

Instantly share code, notes, and snippets.

@tranduclinh2067
Created January 12, 2019 06:14
Show Gist options
  • Save tranduclinh2067/c64a2ba131c99e101a35bfafdaaba1df to your computer and use it in GitHub Desktop.
Save tranduclinh2067/c64a2ba131c99e101a35bfafdaaba1df to your computer and use it in GitHub Desktop.
//MAP
let arr1 = [1,2,4];
let arr2 = arr1.map(X=>X*2);
console.log(arr2); //[2, 4, 8]
console.log(arr1); //[1, 2, 4]
//Việc thực thi mảng sẽ diễn ra theo trình tự clone rồi mới sửa (tránh phá nát mảng ban đâu), sau đó đưa kết quả cho arr2.
//FILTER
let arr1 = [1,2,4];
let arr2 = arr1.filter(X=>X>3);
console.log(arr2); //[4]
console.log(arr1); // [1, 2, 4]
//Xét điều kiện tửng phần tử có trong mảng, clone các phần tử đạt yêu cầu rồi đưa kết quả cho arr2.
//REDUCE
let arr1 = [3,1,7];
let op = arr1.reduce((bien_tam,x)=>x+bien_tam,15);
console.log(op); //(3+1+7)+15 = 26
//Các phần tử trong mảng được xử lý theo các phép tính (tích dần kết quả) cộng với (giá trị mặc định).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment