Now the people at Poplar Puzzles would like you to treat an array of functions like a Queue, passing the result of each function into the next until the Queue is empty. They’ve sent you the new queue of functions, and a “simple directive”:

In a variable called applyAndEmpty, build and store a function that takes in a single number and any Queue of functions as inputs and then applies the Queue’s functions in order to the input number, where the results of each function become the next function’s input. Additionally, the queue should be empty following your application. Lastly, because we are just that freaking awesome, any loops you use must only be for-loops. MWAHAHA. Then call your new function using the number 2 and the provided puzzlers queue as initial inputs, and alert the result.- PuZzLe MaSTeRs

The new Queue of functions to use is below.

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; }
];

We’ve provided the queue and the start value for you.

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; }
];
var start = 2;
var applyAndEmpty = function(num){
puzzlers.map(function(func){
var res = func(num);
num = res;
alert(res);
return res;
});
};
applyAndEmpty(start);
function buildNow(){

  return (function(){

    alert("RUN NOW");
})(); // <<---- We add '()', so that as soon as this function return, it will Immediately invoke.
}
buildNow(); function buildWhenICall(){ return function(){ alert("You call me!");
};
} buildWhenICall()(); // <<--- Or we can do something like that
// The same as
//var run = buildWhenICall();
//run();

[Javascipt] Immediately-Invoker 2的更多相关文章

  1. javascipt的【函数表达式】

    函数表达式 在编程时,我们可以看到不管是什么类库,jquery也好,zepto也好,都会用到大量的命名函数和匿名函数表达式,本节点就是为了弄懂为何会有这些函数表达式,以及在什么情况下会使用到这些表达式 ...

  2. Spring远程调用技术<3>-Spring的HTTP Invoker

    前面提到RMI使用java标准的对象序列化机制,但是很难穿透防火墙.  另一方面,Hessian和Burlap能很好地穿透防火墙,但是使用私有的对象序列化机制. Spring提供的http invke ...

  3. [Android Tips] 23. How to fail/stop Gradle task immediately if some conditions are not met

    throw new GradleException("conditions are not met") 参考 How to fail/stop task immediately i ...

  4. How to force the UI to refresh immediately(WPF)

    Question 0 Sign in to vote Folks, In my application, when the user hits "Submit" button, I ...

  5. 关于JavaScipt对象的基本知识

    关于JavaScipt对象的基本知识 JavaScript是运用“对象化编程”的,又叫“面向对象编程”的.所谓“对象化编程”,意义是把JavaScript能涉及的领域划分成各种对象,对象后面还连续划分 ...

  6. ZOJ 1808 Immediately Decodable

    字典树较简单题,无需维护标记,注意细节即可. 代码: #include <iostream> #include <cstdio> #include <cstring> ...

  7. JBOSS /invoker/JMXInvokerServlet 利用工具 .

    链接: http://pan.baidu.com/s/1F8bMI 密码: 1h2r 工具使用说明 1. 查看系统名称 java -jar jboss_exploit_fat.jar -i http: ...

  8. 服务调用方案(Spring Http Invoker) - 我们到底能走多远系列(40)

    我们到底能走多远系列(40) 扯淡:  判断是否加可以效力于这家公司,一个很好的判断是,接触下这公司工作几年的员工,了解下生活工作状态,这就是你几年后的状态,如果满意就可以考虑加入了. 主题: 场景: ...

  9. HDU 3923 Invoker(polya定理+逆元)

    Invoker Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 122768/62768 K (Java/Others)Total Su ...

  10. Spring Remoting by HTTP Invoker Example--reference

    Spring provides its own implementation of remoting service known as HttpInvoker. It can be used for ...

随机推荐

  1. [BZOJ5317][JSOI2018]部落战争(闵可夫斯基和)

    对于点集$A$,$B$,闵可夫斯基和$C=\{(x1+x2,y1+y2)|(x1,x2)\in A,(y1,y2)\in B\}$.由此可知,对于两个凸包$A$,$B$的闵可夫斯基和$C$满足,$C$ ...

  2. BZOJ.4516.[SCOI2016]幸运数字(线性基 点分治)

    题目链接 线性基可以\(O(log^2)\)暴力合并.又是树上路径问题,考虑点分治. 对于每个点i求解 LCA(u,v)==i 时的询问(u,v),只需求出这个点到其它点的线性基后,暴力合并. LCA ...

  3. Windows 0day成功验证之ETERNALBLUE

    本帖由春秋首发~作者:神风 @春秋文阁负责人 方程式又一波0day[该贴有工具]:https://bbs.ichunqiu.com/thread-21736-1-1.html 最近一段时间出现一波高潮 ...

  4. BZOJ3473 字符串 广义后缀自动机

    今天主攻了下SAM 好多东西以前都没理解到 对于这道题 我们建一个自动机存所有串 每个穿last从1开始 对于自动机上每个点额外记一个cnt 表示能匹配到这个点的不同串个数 建完对每个串在自动机上匹配 ...

  5. 从 n 个数字中选出 m 个不同的数字,保证这 m 个数字是等概率的

    问题如上. 这是我被面试的一个题目. 我的第一反应给出的解决的方法是.开启  n 个线程并标记序号,各个线程打印出它的序号.直到有 m 个线程被调度时,停止全部线程. 打印出的序号即是 m 个等概率出 ...

  6. 关于错误errno EFAULT:Bad address

    UDP socket : read error Bad address 在写UDP server.在调用套接字读取的时候发生了这个错误. 通过看errno.h 能够看到相应的错误号  EFAULT: ...

  7. Windows Phone SDK 8/8.1 官方下载

    Windows Phone SDK 8.1 update英文版http://download.microsoft.com/download/E/7/D/E7D9744A-06A6-46FB-AEA4- ...

  8. BitmapFactory.Options.inSampleSize 的使用方法

    BitmapFactory.decodeFile(imageFile); 用BitmapFactory解码一张图片时.有时会遇到该错误. 这往往是因为图片过大造成的. 要想正常使用,则须要分配更少的内 ...

  9. C#程序集系列05,让程序集包含多个module

    本篇体验在一个程序集中包含多个module. □ 创建3个module →删除F盘as文件夹中的一些文件,只剩下如下3个文件→用记事本打开MyFirstModule.cs文件,修改如下,并保存 usi ...

  10. Maven私仓配置

    <?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://mav ...