[Javascipt] Immediately-Invoker 2
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 providedpuzzlersqueue 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的更多相关文章
- javascipt的【函数表达式】
函数表达式 在编程时,我们可以看到不管是什么类库,jquery也好,zepto也好,都会用到大量的命名函数和匿名函数表达式,本节点就是为了弄懂为何会有这些函数表达式,以及在什么情况下会使用到这些表达式 ...
- Spring远程调用技术<3>-Spring的HTTP Invoker
前面提到RMI使用java标准的对象序列化机制,但是很难穿透防火墙. 另一方面,Hessian和Burlap能很好地穿透防火墙,但是使用私有的对象序列化机制. Spring提供的http invke ...
- [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 ...
- 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 ...
- 关于JavaScipt对象的基本知识
关于JavaScipt对象的基本知识 JavaScript是运用“对象化编程”的,又叫“面向对象编程”的.所谓“对象化编程”,意义是把JavaScript能涉及的领域划分成各种对象,对象后面还连续划分 ...
- ZOJ 1808 Immediately Decodable
字典树较简单题,无需维护标记,注意细节即可. 代码: #include <iostream> #include <cstdio> #include <cstring> ...
- JBOSS /invoker/JMXInvokerServlet 利用工具 .
链接: http://pan.baidu.com/s/1F8bMI 密码: 1h2r 工具使用说明 1. 查看系统名称 java -jar jboss_exploit_fat.jar -i http: ...
- 服务调用方案(Spring Http Invoker) - 我们到底能走多远系列(40)
我们到底能走多远系列(40) 扯淡: 判断是否加可以效力于这家公司,一个很好的判断是,接触下这公司工作几年的员工,了解下生活工作状态,这就是你几年后的状态,如果满意就可以考虑加入了. 主题: 场景: ...
- HDU 3923 Invoker(polya定理+逆元)
Invoker Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 122768/62768 K (Java/Others)Total Su ...
- Spring Remoting by HTTP Invoker Example--reference
Spring provides its own implementation of remoting service known as HttpInvoker. It can be used for ...
随机推荐
- GNU C __attribute__ 机制简介
摘要: 在学习linux内核代码及一些开源软件的源码(如:DirectFB),经常可以看到有关__attribute__的相关使用.本文结合自己的学习经历,较为详细的介绍了__attribute__相 ...
- PAT甲级1114. Family Property
PAT甲级1114. Family Property 题意: 这一次,你应该帮我们收集家族财产的数据.鉴于每个人的家庭成员和他/她自己的名字的房地产(房产)信息,我们需要知道每个家庭的规模,以及他们的 ...
- SQL 死锁进程查询
use master go declare @spid int,@bl int DECLARE s_cur CURSOR FOR ,blocked ) a ) b where a.blocked=sp ...
- CentOS6.X关闭防火墙
一.关闭防火墙 1.重启后永久性生效: 开启:chkconfig iptables on 关闭:chkconfig iptables off 2.即时生效,重启后失效: 开启:service ipta ...
- mysql另类分页方法
mysql> limit ,;select found_rows(); +----+-----------------+---------+--------+ | id | rankName | ...
- Apache 如何反向代理tomcat并且实现Session保持
简介 LAMT=Linux+Apache+MySQL+Tomcat: Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器: 在中小型系统和并发访问用户不是很多的场合下 ...
- HK设备安全补丁升级方案
1.背景: 当前很多HK行业设备的端口映射到公网上,其中一部分老版本设备是存在安全漏洞的,由于传统行业没有设备平台的概念,无法通过设备提示用户进行升级,导致这些存在漏洞的设备在互联网 ...
- jquery.uploadify 使用过程
HTML: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"& ...
- Node.js modules you should know about: request
Hey everyone! This is the fourth post in my new node.js modules you should know about article series ...
- 系统字体的Regular、Light等几种名称的区别
以苹果系统中的PingFang SC系列字体为例,其中常见的有下面几种类型可以细分如下. PingFang SC ExtraLight 苹方 特细 PingFang SC Light ...