0031【Edabit ★☆☆☆☆☆】【使用箭头函数】Using Arrow Functions
data_structures
language_fundamentals
Instructions
Create a function that returns the given argument, but by using an arrow function.
An arrow function is constructed like so:
javascript
arrowFunc=(/*parameters*/)=>//code here
Examples
javascript
arrowFunc(3) // 3
arrowFunc("3") // "3"
arrowFunc(true) // true
Notes
- N/A
Solutions
javascript
// create your arrow function below
arrowFunc = (parameter) => parameter ;
TestCases
javascript
let Test = (function(){
return {
assertEquals:function(actual,expected){
if(actual !== expected){
let errorMsg = `actual is ${actual},${expected} is expected`;
throw new Error(errorMsg);
}
}
}
})();
if(!(String(arrowFunc).includes('=>'))){
Test.assertEquals(0,1,"Your code does not use an arrow function")
}
Test.assertEquals(arrowFunc(3),3)
Test.assertEquals(arrowFunc("3"),"3")
Test.assertEquals(arrowFunc(true),true)
Test.assertEquals(arrowFunc("test"),"test")