[CoffeeScript] Level 4 Arrays, Objects, Iterations -- Ex
Coffee on the Range
Create an array with numbers 1 until 10 using the inclusive (two dot) range syntax.
[1..10]
Coffee on the Range II
Create an array with numbers 1 through 10 using the exclusive range syntax.
Exclusive ranges are defined using three dots between integers, inside square brackets
[1...6] Exclusive ranges do not include the last number.
values = [1...5]
# this expands to [1, 2, 3, 4] The answer is
[1...11]
Object Literals
Create a variable named coffee which is an object with a name property set to 'Russian', alevel property set to 2 and an isRussian property which holds a function that returns true. Use an object literal.
coffee =
name: 'Russian'
level: 2
isRussian: ->
true
or In Loop
Using the for element in collection loop, iterate over the people collection and print the names of people over 18 years old (person.age > 18). Use the console.log function to print the person.name.
for person in people
console.log(person.name) if person.age > 18
List Comprehension
Modify the loop below to use a list comprehension.
console.log "#{person.name}" for person in people when person.age > 18
List Comprehension II
Refactor the code below to make use of list comprehension.
addCoffee coffee for coffee in coffeeList when not coffee.isRussian?()
Splat Arguments
Change the displayTopPicks function to accept a variable number of suggested coffees by using the splat operator. Use suggested.join(", ") to alert all of the suggested coffees.
displayTopPicks = (bestCoffee, suggested...) ->
alert('Top #1 ' + bestCoffee)
alert('Suggested: ' + suggested.join(","))
[CoffeeScript] Level 4 Arrays, Objects, Iterations -- Ex的更多相关文章
- coffeescript 1.8.0 documents
CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque ...
- coffeescript 1.6.3使用帮助
CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque ...
- Tempo 2.0
Tempo 2.0 Tempo is an easy, intuitive JavaScript rendering engine that enables you to craft data tem ...
- how to use coffee script
TABLE OF CONTENTS TRY COFFEESCRIPT ANNOTATED SOURCE CoffeeScript is a little language that compiles ...
- mysql 5.7.17发布
Mysql 5.7.17发布了,主要修复: Changes in MySQL 5.7.17 (2016-12-12, General Availability) Compilation Notes M ...
- Attacking JavaScript Engines: A case study of JavaScriptCore and CVE-2016-4622(转)
转:http://phrack.org/papers/attacking_javascript_engines.html Title : Attacking JavaScript Engines: A ...
- Zend API:深入 PHP 内核
Introduction Those who know don't talk. Those who talk don't know. Sometimes, PHP "as is" ...
- iPhone Tutorials
http://www.raywenderlich.com/tutorials This site contains a ton of fun written tutorials – so many t ...
- Faster, more memory efficient and more ordered dictionaries on PyPy
Faster, more memory efficient and more ordered dictionaries on PyPy https://morepypy.blogspot.com/20 ...
随机推荐
- ajax 访问--提高安全性
首先受到struts token的启发,产生了客户端发起的ajax请求进行验证的想法,大致思路是客户端每次请求产生一个key ,然后服务端接收到key,然后解析,判断是否为合法key, 对于不带key ...
- The serializable class does not declare a static final serialVersionUID field of type long
在编译以下Java程序时,出现The serializable class does not declare a static final serialVersionUID field of typ ...
- 开扒php内核函数,第一篇 bin2hex
这段时间真的比较有时间,所以自己用c写一下bin2hex啦 写个php的人都知道,这是个比较熟悉的函数吧,没有什么高深,只是把输入的东西以16进制输出吧了 先分析一下,这个函数要怎么写吧,他会有一定的 ...
- 初识MFC,WinForm,WPF,Q't
MFC和QT是C++中常见的GUI框架,而WinForm和WPF是C#中常用的框架,不过我们一般很少叫WinForm框架,可能直接叫图形控件类库更多点.反正只是个称呼罢了,爱咋叫就咋叫.另外WinFo ...
- effective c++:对象的赋值运算
operator 中处理”自我赋值“ operator=操作符缺省情况下返回引用——TYPE& TYPE::operator=(const TYPE&),原因很简单,operator= ...
- Google软件测试
google测试相关的职位有三类:软件测试开发工程师.测试工程师以及测试工程经理. 软件测试开发工程师也是一个开发角色,只是工作重心在可测试性和通用测试框架上.他们参与设计评审,非常近距离地观察代码质 ...
- erlang 基础知识
一 数据类型 1. 整数 Integer Erlang可表示任意大的整数,大整数自动转换成bignums类型,比固定大小的整数类型相对效率较低. Base#Value 表示基数不是10的整数.如:2# ...
- 第三百五十九天 how can I 坚持
在家待了一天,鼓捣了下linux,总算能连上网了,懂得还是少啊. 晚上去华北电力大学跑了会步,十圈,还挺有成就感呢,就是没带手环,哎. 以后学习一定要记笔记,上了这么多年学,都 没学会怎么记笔记,也是 ...
- 转】使用Maven编译项目遇到——“maven编码gbk的不可映射字符”解决办法
原博文出自于: http://www.cnblogs.com/xdp-gacl/p/4239006.html 感谢! 一.问题描述 今天在MyEclipse中使用Maven编译项目源代码时,结果如下了 ...
- 安装php5.5
安装php5.5 ./configure --prefix=/usr/local/php5.5.14/ --with-apxs2=/usr/local/apache2.2.27/bin/apxs -- ...