-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimization of the adjustNumber function #107
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ const hexToInt = function(bytes) { | |
byte = parseInt(hex, 16) | ||
} else { | ||
throw new Error( | ||
`Wrong format of element ${hex} in byte array ${bytes}\nShould be either integer of hexadecimal starting with '0x'` | ||
`Wrong format of element ${hex} in byte array ${bytes}\nShould be either integer of hexadecimal starting with '0x'` | ||
) | ||
} | ||
return byte | ||
|
@@ -38,19 +38,16 @@ const hexToInt = function(bytes) { | |
* @return {Array.<Number>} - Adjusted byte array | ||
*/ | ||
const adjustNumber = function(bytes) { | ||
if (bytes.length === 8) { | ||
const number = bytesOf( | ||
if (bytes.length !== 8) return bytes; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Akvadevka we're trying to avoid many |
||
|
||
const number = bytesOf( | ||
new DataView(new Int8Array(bytes).buffer).getBigInt64(0) | ||
).asBytes() | ||
return bytes.map((byte, index) => { | ||
if (Math.abs(byte - number[index]) === 256) { | ||
return byte - 256 | ||
} | ||
return byte | ||
}) | ||
} | ||
return bytes | ||
} | ||
).asBytes(); | ||
|
||
return bytes.map((byte, index) => | ||
Math.abs(byte - number[index]) === 256 ? byte - 256 : byte | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Akvadevka I don't see the purpose of the change. Replacing |
||
); | ||
}; | ||
|
||
/** | ||
* Bytes of. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Akvadevka there's something wrong with indentation