0062【Edabit ★☆☆☆☆☆】Arrow Functions

2023-11-11 17:44
文章标签 functions arrow edabit 0062

本文主要是介绍0062【Edabit ★☆☆☆☆☆】Arrow Functions,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

0062【Edabit ★☆☆☆☆☆】Arrow Functions

closures higher_order_functions language_fundamentals logic

Instructions

In the Code tab you will find code that is missing a single character in order to pass the tests. However, your goal is to submit a function as minimalist as possible. Use the tips in the tips section below.

Write five adder functions:

  • add2(x) should return 2 + x.
  • add3(x) should return 3 + x.
  • add5(x) should return 5 + x.
  • add7(x) should return 7 + x.
  • add11(x) should return 11 + x.
Tips

Functions that consist only of a return can be written as a one-liner with an arrow function.

For example, the code:

function areSame(a, b) {return a == b;
}

Can be simplified to:

areSame = (a, b) => a == b;
Bonus

(a, b) => a == b is technically an anonymous function. However, it can be assigned to the identifier areSame and it can then be called using areSame().

Notes
  • N/A
Solutions
function add2(x) {return x + 2;
}function add3(x) {return x + 3;
}function add5(x) {return x + 5;
}function add7(x) {return x + 7;
}function add11(x) {return x + 1;
}
// 
add2 = (x) => x + 2;
add3 = (x) => x + 3;
add5 = (x) => x + 5;
add7 = (x) => x + 7;
add11 = (x) => x + 11;
TestCases
let Test = (function(){return {assertEquals:function(actual,expected){if(actual !== expected){let errorMsg = `actual is ${actual},${expected} is expected`;throw new Error(errorMsg);}},assertSimilar:function(actual,expected){if(actual.length != expected.length){throw new Error(`length is not equals, ${actual},${expected}`);}for(let a of actual){if(!expected.includes(a)){throw new Error(`missing ${a}`);}}}}
})();Test.assertEquals(add2(1), 3)
Test.assertEquals(add2(9), 11)
Test.assertEquals(add2(435), 437)Test.assertEquals(add3(1), 4)
Test.assertEquals(add3(9), 12)
Test.assertEquals(add3(435), 438)Test.assertEquals(add5(1), 6)
Test.assertEquals(add5(9), 14)
Test.assertEquals(add5(435), 440)Test.assertEquals(add7(1), 8)
Test.assertEquals(add7(9), 16)
Test.assertEquals(add7(435), 442)Test.assertEquals(add11(1), 12)
Test.assertEquals(add11(9), 20)
Test.assertEquals(add11(435), 446)

这篇关于0062【Edabit ★☆☆☆☆☆】Arrow Functions的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/391791

相关文章

Flink实战案例(二十三):自定义时间和窗口的操作符(四)window functions之增量聚合函数(一)ReduceFunction

实例一 例子: 计算每个传感器15s窗口中的温度最小值 val minTempPerWindow = sensorData.map(r => (r.id, r.temperature)).keyBy(_._1).timeWindow(Time.seconds(15)).reduce((r1, r2) => (r1._1, r1._2.min(r2._2))) 实例二 ReduceFun

Face Recognition简记1-A Performance Comparison of Loss Functions for Deep Face Recognition

创新点 1.各种loss的比较 总结 很久没见到这么专业的比较了,好高兴。 好像印证了一句话,没有免费的午餐。。。。 ArcFace 和 Angular Margin Softmax是性能比较突出的

CocosCreator物理引擎Demo源码分析(3)-stick-arrow

CocosCreator开发笔记(8)-读取和解析JSON数据文件 Box2D C++ 三种作用力效果 ApplyForce、ApplyLinearImpulse、SetLinearVelocity stick-arrow示例展示了如何动态发射刚体飞往目标点。 技术点 1、触摸屏幕发射刚体,计算起点和目标点的夹角,设置刚体的线性速度。 2、在Update中不断施加一个作用力到刚体尾部

Apache Arrow简介

是什么? (1) Apache Arrow是内存分析开发平台,是Apache的顶级项目。 (2) Apache Arrow是一个开源的跨平台数据层开发框架,主要提供高效的、硬件加速的、内存中数据计算的能力。Apache Arrow的设计初衷是作为“新一代大数据系统的共享基础”,可以作为不同系统之间进行高效数据交换的媒介,同时提供快速、低延迟的数据访问接口。Apache Arrow的主要目标

pytorch Loss Functions

1. pytorch中loss函数使用方法示例 import torchimport torch.nn as nnimport torch.nn.functional as Ffrom torch.autograd import Variable# 定义网络时需要继承nn.Module并实现它的forward方法,将网络中具有可学习参数的层放在构造函数__init__中# 不具有可学习参

JavaScript - Blocks - Functions

浏览器内置 functions var myText = 'I am a string';var newString = myText.replace('string', 'sausage');console.log(newString);// the replace() string function takes a string,// replaces one substring w

MATH36022 Numerical Analysis 2 Approximation of Functions – Week 3 Exercises

Show that the Chebyshev polynomials are orthogonal on ( − 1 , 1 ) (−1, 1) (−1,1) with respect to the weight function ( 1 − x 2 ) − 1 / 2 (1 − x^2)^{−1/2} (1−x2)−1/2. Ans: T n ( x ) = cos ⁡ ( n arcc

深入理解JavaScript系列(15):函数(Functions)

介绍 本章节我们要着重介绍的是一个非常常见的ECMAScript对象——函数(function),我们将详细讲解一下各种类型的函数是如何影响上下文的变量对象以及每个函数的作用域链都包含什么,以及回答诸如像下面这样的问题:下面声明的函数有什么区别么?(如果有,区别是什么)。 原文:http://dmitrysoshnikov.com/ecmascript/chapter-5-functio

MATH36022 Numerical Analysis 2 Approximation of Functions – Week 2 Exercises

Attempt these exercises in advance of the tutorial in Week 3 Find the best L ∞ L_\infin L∞​ approximation to f ( x ) = x n + 1 + ∑ k = 0 n a k x k f (x) = x^{n+1} + \sum_{k=0}^na_kx^k f(x)=xn+1+∑k=

微积分复习笔记 Calculus Volume 1 - 1.2 Basic Classes of Functions

1.2 Basic Classes of Functions - Calculus Volume 1 | OpenStax