Skip to content

Instantly share code, notes, and snippets.

@jonahsnider
Last active June 19, 2023 23:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonahsnider/7f0f8dd69f591b8e40b1ee38f0285403 to your computer and use it in GitHub Desktop.
Save jonahsnider/7f0f8dd69f591b8e40b1ee38f0285403 to your computer and use it in GitHub Desktop.
Get the value 4 in Node.js
const four = () => process.toString().big().endsWith(String.fromCharCode(18 + ((process.toString().substring(1, 2).charCodeAt(Number.MIN_VALUE)) * 4) - Math.pow(20, 2))).toString().length;
console.log(four()); // 4
const assert = require("assert");
const fourButReadable = () => {
// String that contains an o as the second character
const objectInString = process.toString();
assert.strictEqual(objectInString, "[object process]");
// `objectInString` is randomly used, any string would work here
// This adds a `>` to the end of the string
const htmlString = objectInString.big();
assert.ok(htmlString.endsWith(">"));
// Next we want to generate a value that is equal to `true`, so that when converted to a string it's 4 characters long
// This is done by comparing the last digit of `htmlString` and the character `>`, which is assembed with `String#fromCharCode`
// The letter o
const o = process.toString().substring(1, 2);
assert.strictEqual(o, "o");
// The char code of o is 111
// `Number.MIN_VALUE` is rounded to zero.
const aHundredAndEleven = o.charCodeAt(Number.MIN_VALUE);
assert.strictEqual(aHundredAndEleven, 111);
assert.strictEqual(o.charCodeAt(Number.MIN_VALUE), o.charCodeAt(0));
// Multiply by 4
const fourHundredFourtyFour = aHundredAndEleven * 4;
assert.strictEqual(fourHundredFourtyFour, 444);
// Subtract 400
const fortyFour = fourHundredFourtyFour - Math.pow(20, 2);
assert.strictEqual(fortyFour, 44);
// Now we add 18 to 44 to get 62, the character code of `>`
const greaterThanCharCode = 18 + fortyFour;
assert.strictEqual(greaterThanCharCode, 62);
// Get `true` value
const stringEndsWithGreaterThanSymbol = htmlString.endsWith(String.fromCharCode(greaterThanCharCode));
assert.strictEqual(stringEndsWithGreaterThanSymbol, true);
const fourCharacterString = stringEndsWithGreaterThanSymbol.toString();
assert.strictEqual(fourCharacterString.length, 4);
return fourCharacterString.length;
}
console.log(fourButReadable());
@MicroDroid
Copy link

MicroDroid commented Apr 2, 2020

amazing, but how do I use this in a loop? I've been thinking of this but I don't think it's high performance:

for (let i = 0; i < // String that contains an o as the second character
  const objectInString = process.toString();
  assert.strictEqual(objectInString, "[object process]");

  // `objectInString` is randomly used, any string would work here
  // This adds a `>` to the end of the string
  const htmlString = objectInString.big();
  assert.ok(htmlString.endsWith(">"));

  // Next we want to generate a value that is equal to `true`, so that when converted to a string it's 4 characters long
  // This is done by comparing the last digit of `htmlString` and the character `>`, which is assembed with `String#fromCharCode`
  
  // The letter o
  const o = process.toString().substring(1, 2);
  assert.strictEqual(o, "o");

  // The char code of o is 111
  // `Number.MIN_VALUE` is rounded to zero.
  const aHundredAndEleven = o.charCodeAt(Number.MIN_VALUE);
  assert.strictEqual(aHundredAndEleven, 111);
  assert.strictEqual(o.charCodeAt(Number.MIN_VALUE), o.charCodeAt(0));

  // Multiply by 4
  const fourHundredFourtyFour = aHundredAndEleven * 4;
  assert.strictEqual(fourHundredFourtyFour, 444);

  // Subtract 400
  const fortyFour = fourHundredFourtyFour - Math.pow(20, 2);
  assert.strictEqual(fortyFour, 44);

  // Now we add 18 to 44 to get 62, the character code of `>`
  const greaterThanCharCode = 18 + fortyFour;
  assert.strictEqual(greaterThanCharCode, 62);

  // Get `true` value
  const stringEndsWithGreaterThanSymbol = htmlString.endsWith(String.fromCharCode(greaterThanCharCode));
  assert.strictEqual(stringEndsWithGreaterThanSymbol, true);

  const fourCharacterString = stringEndsWithGreaterThanSymbol.toString();
  assert.strictEqual(fourCharacterString.length, 4);

  return fourCharacterString.length;
; i++) {
 //
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment