signum.js

 /**signum

A signum function returns 1 for numbers greater than zero and -1 for numbers less than zero
and 0 for an input of 0. Write a signum implementation that takes a float N and returns
an integer.

Input
One line containing a decimal number.

N

Output
One integer, denoting the output value.

Example
Input:

-0.87

Output:

-1
*/

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


let fs = require("fs");
let data = fs.readFileSync(0, 'utf-8');
let idx = 0;
data = data.split('\n');

function readLine() {
idx++;
return data[idx - 1];
}



function signum(a) { // declaring the signum function ,a is the parameter

if (a > 0)
return 1

else if (a < 0)
return -1

else if (a == 0)
return 0

}

const integer = signum(parseFloat(readLine())); // -0.87 calling invoking the function signum
//or
//console.log(signum(integer)) // directly consoling and invoking a function togehter.

console.log(integer);

///////////////////////////////////////////////////////////////////////////////////////////////

TERMINAL:








Comments

Popular posts from this blog

car.js

movie.js