|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
498 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var $floor = require('math-intrinsics/floor');
|
|---|
| 4 |
|
|---|
| 5 | // https://runestone.academy/ns/books/published/pythonds/BasicDS/ConvertingDecimalNumberstoBinaryNumbers.html#:~:text=The%20Divide%20by%202%20algorithm,have%20a%20remainder%20of%200
|
|---|
| 6 |
|
|---|
| 7 | module.exports = function intToBinaryString(x) {
|
|---|
| 8 | var str = '';
|
|---|
| 9 | var y;
|
|---|
| 10 |
|
|---|
| 11 | while (x > 0) {
|
|---|
| 12 | y = x / 2;
|
|---|
| 13 | x = $floor(y); // eslint-disable-line no-param-reassign
|
|---|
| 14 | if (y === x) {
|
|---|
| 15 | str = '0' + str;
|
|---|
| 16 | } else {
|
|---|
| 17 | str = '1' + str;
|
|---|
| 18 | }
|
|---|
| 19 | }
|
|---|
| 20 | return str;
|
|---|
| 21 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.