use map(),forEach() method
let arr:number[]=[1,2,3];
let b:<Array>number=arr.map((item:number)=>item*item);
arr.forEach((item:number)=>console.log(item));
curried function
let add=(m:number)=>(n:number)=>m*n;
add(4)(3) //12;
let add3=add(4);
add3(4);// 16;
compose function
let compose=(f,g)=>x=>f(g(x));
let f=x=>x.toUpperCase();
let g=x=>x+'!';
let useCompose=compose(f,g);
console.log(useCompose('xixi')); //XIXI!
reference **recommend **
this article is too difficult to read ,so that I will update in the future when I understand it.
Question
solution
const extname = (filename) => {
let string = Array.from(filename.toString());
let index = string.findIndex((val, index, arr) => val == '.');
let strL = string.length;
let index2 = string.reverse().findIndex((val, index, arr) => val == '.');
if (index < 1) {
return filename.substr(strL, 0);
} else {
index == strL - index2 ? index = index : index = strL - index2;
return filename.substring(index - 1, strL)
}
}
extname('.hello'); //''
extname('fadfa.jpg'); //.jpg
extname('fda.gad.jj'); //.jj
extname('gafgad,jpg'); //''
📌update 11.16.2017
methods
- map()
let a:Array<number>=[1,2,3,4,5]
let b:number[]=a.map(item=>item*item)
- reduce()
let a:Array<number>=[1,2,3,4,5];
let b:number=a.reduce((sum,val)=>sum+=val);
- filter()
let a:Array<number>=[1,2,3,4,5];
let b:number[]=a.filter(val=>val>2)