Arrow Functions - Javascript
If the entered number is even number add 1.
var h = [2,8,12,47];
var f=h.filter(x=> x%2==0).map(y=>y+1);
In here, filter() does logical processing and map() function do addition process.
Other example containing test(),replace() functions.
----Old output----
My old friend is very clever.
---New output---
My best friend is very clever.
var h = [2,8,12,47];
var f=h.filter(x=> x%2==0).map(y=>y+1);
In here, filter() does logical processing and map() function do addition process.
Other example containing test(),replace() functions.
const myReplace=str1=>{
"use strict";
const chStr=/old/;
const myString="My old friend is very clever.";
return chStr.test(myString) ? myString.replace(chStr,str1) : NaN;
};
print(myReplace("best"));
----Old output----
My old friend is very clever.
---New output---
My best friend is very clever.
Comments