Echo JS 0.11.0

<~>
photopea 2543 days ago.
There is a tool, which simplifies JS code: https://prepack.io/repl.html

You have to write a program, that prints the current timestamp: Date.now(), and is located in an anonymous function, i.e. between "(function(){"  and  "})()".

But it should not contain "Date.now()" in a simplified version.

My first attempt:
(function(){
console.log(window["Da"+"te"]["no"+"ow".charAt(1)]());
})();

... but the right side does contains Date.now(). Can you "outsmart" that tool?

sylvainpv 2542 days ago. link 2 points
The goal is to evaluate the function with a runtime condition, so that prepack is forced to keep the dynamic evaluation. This can be done with Math.random() or +(new Date()) or many environment properties, but none of them are supported by Prepack. Any runtime-dependent expression throws an IntrospectionError:

console.log(Date[Math.random() > 0 ? "now" : "nope"]())
sashee 2542 days ago. link 1 point
Well, it crashes the tool but passes all the requirements:

(function(){
  var fn = Math.random() <= 1 ? "Date": "";
  console.log(window[fn].now());
})();

Output:
TODO
__IntrospectionError
    at repl:3:22
    at repl:1:1
photopea 2542 days ago. link 1 point
It is very similar to the previous solution :)
calois 2542 days ago. link 1 point
Not sure about the code below:

(function(){
  var v = Math.ceil(Math.random()*1000);
  for(var i=0;i<5;i++){
	  v = Math.ceil(v/10);
  }
  var t = ['ac','te'];
  console.log(window["Da"+t[v]]["no"+"ow".charAt(1)]());
})();
photopea 2542 days ago. link 1 point
The task was a program, that always prints a timestamp, but your program prints it "almost always" (when random has not returned a zero). I am not sure if it is a solution, but I like it very much! :)

I wonder if there could be a better solution without randomness.
Swizz 2542 days ago. link 0 point
Another contrib, less exotic than the first one, I did :

(function(){
  console.log(window[
      (13)["toString"](36).toUpperCase() + 
      (10)["toString"](36) +
      (29)["toString"](36) +
      (14)["toString"](36)
    ][
      (23)["toString"](36) +
      (24)["toString"](36) +
      (32)["toString"](36)
    ]
    ()
  )
})();
photopea 2542 days ago. link 1 point
This one does contain "Date.now()" on the right simplified side.