Multi Requirements: All tasks must be written in JavaScript. You can only use



Yüklə 18,86 Kb.
tarix10.12.2022
ölçüsü18,86 Kb.
#120772
Primary test Frontend (3)


Primary test

  1. You get necessary to acquainted with the requirements

  2. Solve the problem of "multi"

Requirements:
All tasks must be written in JavaScript. You can only use following native operators in our examples and you cannot initialize any extra variables.

(a + b), (a - b)

arithmetic operations

(a > b), (a < b), (a == b)

comparison operations

(a && b), (a || b), (!a)

logical operations

if (predicate){ thenBody }
else {elseBody}



conditional operation

function (spec) {body}

defining custom functions

Don’t use loops, switch or any other JavaScript operators, also functions and plugins
Example-1.
function sign(n){
if (n > 0) return 1;
else return -1;
}

  • sign(2)

1

  • sign(-5)

-1
Example-2. (n > 1) The sum of numbers from 1 to n
function sum(n) {
if (n == 1) return 1;
else sum(n - 1) + n;
}

  • sum(4) => 10

Evaluation:
((sum(3) + 4)
((sum(2) + 3) + 4)
((sum(1) + 2) + 3) + 4)
((1 + 2) + 3) + 4)
((3 + 3) + 4)
(6 + 4) => 10


Task:
Write a function of multiplication (*).
Input: a and b are any positive integers
Output: only one positive integer
function multi(a, b) {

}

  • multi(3, 4)

12
Yüklə 18,86 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©muhaz.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin