Skip to content

Instantly share code, notes, and snippets.

View tj-commits's full-sized avatar
💭
BACK FROM THE GHOST

tj-commits tj-commits

💭
BACK FROM THE GHOST
View GitHub Profile
@tj-commits
tj-commits / binary2decimal.js
Created March 1, 2025 17:30
JavaScript function to convert from binary to decimal
const IS_BINARY_REGEX = /^[01]+$/
const reverseString = require('reverse-string')
const { immediateError, ErrorType } = require('immediate-error')
function binary2decimal(binary) {
if (typeof binary !== 'string' && !(binary instanceof String) && typeof binary !== 'number' && !(binary instanceof Number)) {
return immediateError('Binary must be a string or fake decimal number that consists of ones and zeroes and is actually a binary number.', ErrorType.TypeError)
}
binary = binary.toString()
if (!binary.match(IS_BINARY_REGEX)) {
@tj-commits
tj-commits / gist:a8185e53b7310bed3e67bf66c9dede45
Last active September 26, 2024 01:05
Really, really bad javascript

HAVE WE FORGOTteN HOw TO PROGrAM?!?!

function isGreaterThan5(value) {
  if (value > 5) {
    return true;
  } else {
    return false;
  }
}