Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2018
    Thanked 0 Times in 0 Posts

    What this code actually doing, please someone help me to understand!

    I don't understand, What this code actually doing?
    Can someone tell me?
    const checkThatTwoPlusTwoEqualsFourAMillionTimes = () => {
      for(let i = 1; i <= 1000000; i++) {
        if ( (2 + 2) != 4) {
          console.log('Something gone very wrong :( ');
    const addTwo = num => num + 2;
    const timeFuncRuntime = funcParameter => {
      let t1 = Date.now();
      let t2 = Date.now();
      return t2 - t1;
    // Write your code below
    const time2p2 = timeFuncRuntime(checkThatTwoPlusTwoEqualsFourAMillionTimes);
    const checkConsistentOutput = (timeFuncRuntime, val) => {
      let try1 = timeFuncRuntime(val);
      let try2 = timeFuncRuntime(val);
      if (try1 === try2) {
        return try1;
      } else {
        return 'This function returned inconsistent results'
    console.log(checkConsistentOutput(addTwo, 7));

  2. #2
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Keene, NH
    Thanked 470 Times in 458 Posts
    It's mostly pointless gibberish... the 'check' function should never output anything, and doesn't RETURN anything so it serves no real purpose, about the only thing that happens is the data comparison which will occasionally output the 'inconsistent results' due to timer rollover -- the only thing ACTUALLY being tested.

    Of course it's using those stupid malfing arrow functions, aka "wah wah, I'm too lazy to type the word function and could give a flying purple fish about code clarity!"

    90%+ of that code does NOTHING, timer jitter alone (code execution not lining up with the timer interrupt/update) would screw up any chance at meaningful 'results' from it.

    This isn't so much of a question of what it is doing, but WHY?!? What is it TRYING to do? Where did you get this poster child for developer ignorance?
    “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare, The 1980 ACM Turing Award Lecture

  3. Users who have thanked deathshadow for this post:

    Jyotirmoy144 (Sep 30th, 2018)


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts