zoukankan      html  css  js  c++  java
  • Immediately-Invoked Puzzler

     

    The Poplar Puzzle-makers weren’t too impressed. They barely noticed your simple and beautiful array of functions, and were only sort of “meh” on the usage of the array as a queue. But now, they’ve sent you a puzzle, complete with a new set of functions to use on that puzzle. So, to display your overwhelming array and function expression mastery, alert the answer to the following question.

    “What is obtained when the result of passing 9 into function 4 is then passed into the function whose array index matches the result of passing 3 into function 2?”

    var puzzlers = [
      function ( a ) { return 8*a - 10; }, 
      function ( a ) { return (a-3) * (a-3) * (a-3); }, 
      function ( a ) { return a * a + 4; },
      function ( a ) { return a % 5; }
    ];
    

    To really impress the puzzle builders, the expression used in your alert should:

    1. Involve no manual calculation or hard-coded math on your part.
    2. Use indices of arrays to access functions.
    3. Use parentheses to pass in parameters to immediately-invoking functions.
    4. Use just one line of code.
    var puzzlers = [
      function ( a ) { return 8*a - 10; }, 
      function ( a ) { return (a-3) * (a-3) * (a-3); }, 
      function ( a ) { return a * a + 4; },
      function ( a ) { return a % 5; }
    ];
    
    alert((puzzlers[(puzzlers[1])(3)])((puzzlers[3])(9)));
  • 相关阅读:
    【队列】队列的分类和实现
    【JSP】EL表达式语言
    【JSP】JSP的介绍和基本原理
    【JSP】JSP Action动作标签
    【Servlet】关于RequestDispatcher的原理
    【JSP】JSP指令
    【JSP】JSP中的Java脚本
    【算法】表达式求值--逆波兰算法介绍
    C语言指针详解
    移动架构-MVVM框架
  • 原文地址:https://www.cnblogs.com/Answer1215/p/3887470.html
Copyright © 2011-2022 走看看