Skip to content

Instantly share code, notes, and snippets.

@pizzafox

pizzafox/four.js

Last active Oct 19, 2020
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@MicroDroid 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++) {
 //
}
@wuzics

This comment has been minimized.

Copy link

@wuzics wuzics commented Oct 19, 2020

thank you this is very useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.