[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 ...
随机推荐
- MFC学习20160718(GetModuleFileName&&GetAppDataPath)
1.标题栏设置 一.对话框标题栏内容为静态 直接在对话框属性“General”的“Caption”中修改. 二.对话框标题栏内容为动态生成的 在对应对话框的初始化函数OnInitDialog()中添加 ...
- RHadoop教程翻译系列 _Mapreduce(1)_第一个Mapreduce任务
如果单从概念上来说,Mapreduce和R中的函数lapply, tapply并无差别,它们都是把元素转化成列,然后计算索引(Mapreduce中的键),最后合并成一个定义好的组合.首先,让我们看一个 ...
- Java自带webservice
http://blog.sina.com.cn/s/blog_61d8d96401013tmp.html 1.首先创建一个Java项目,作为Web services Endpoint. 2.创建一个H ...
- php 扩展apc 参数优化
编辑php.ini 输入下面 [apc] apc.enabled=1apc.shm_segments = 1apc.shm_size = 1Gapc.ttl = 0apc.user_ttl = 0ap ...
- 企业部署Linux应用将拥有更低的整体拥有成本
企业部署Linux应用将拥有更低的整体拥有成本 使用Linux能为企业的IT解决方案降低TCO(整体拥有成本Total Cost of The Ownership)吗?在面临这个问题时,很多企 ...
- jquery call方法和apply方法接触
call方法: 语法:call([thisObj[,arg1[, arg2[, [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象. 说明: call 方法可以用来 ...
- C++11类型推导
[C++11类型推导] auto 关键字.这会依据该初始化子(initializer)的具体类型产生参数: 除此之外,decltype 能够被用来在编译期决定一个表示式的类型. 参考:http://z ...
- HDU 3923 Invoker(polya定理+逆元)
Invoker Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 122768/62768 K (Java/Others)Total Su ...
- python 递归遍历文件夹
#!/usr/bin/python import os.path def readXmls(folder): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 for ...
- Cisco SDM
SDM连接方式:http+telnet / https+ssh 要使用SDM对CISCO设备实现集中式管理,必须在设备上键入如下命令: 步骤1: 要启用路由器的HTTP/HTTPS 服务器,请 ...