boolean-to-signed
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/boolean-to-signed package

1.0.1 • Public • Published

boolean-to-signed

Returns -1 if input is false, or 1 if input is true.

Install

Install with npm:

$ npm install boolean-to-signed

Usage

const toSigned = require("boolean-to-signed");

console.log(toSigned(false));                  //=> -1
console.log(toSigned(true));                   //=> 1


// use cases
let x, y, value;

// using naive conditional assignment
if (x > 0) {
  y += value;
} else {
  y -= value;
}

// using direct assignment
y += toSigned(x > 0) * value;

About

Author

Najim Islam

License

Copyright © 2021, Najim Islam. Released under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i boolean-to-signed

Weekly Downloads

7

Version

1.0.1

License

MIT

Unpacked Size

1.25 kB

Total Files

3

Last publish

Collaborators

  • najimi