[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 ...
随机推荐
- matlab 之基础使用
dir(xxx,'.jpg') :读取某文件所有jpg格式的图片,并获取图片属性信息 size(x,1) :获得x矩阵多少行 cell(): 申明数组 注释选定代码的快捷操作:Ctrl+R
- C#轻量级企业事务 - TransactionScope
using System; using System.Data.SqlClient; using System.Transactions; namespace SomeDBTransaction { ...
- PHPCMS数据筛选功能实现
第一步:添加模型字段,这个模型可以是官方的,也可以是你自定义的模型,以单选字段形式添加就好了; 第二步:就是添加栏目和内容: 第三步:模板如下,照着改就好了. {template "cont ...
- Iframe的应用以及父窗口和子窗口的相互访问
点评:Iframe和FRAME的区别,方便大家以后在使用过程中根据实际需要取舍.- function getParentIFrameDocument(aID) { var rv = null; // ...
- 桶排序-OC
NSArray * b = @[@,@,@,@,@]; NSMutableArray *a = @[].mutableCopy; ; i<; i++) { a[i] = @; } for (NS ...
- pku1273 Drainage Ditches
http://poj.org/problem?id=1273 网络流,Dinic #include <stdio.h> #include <string.h> #include ...
- RxCache 的代码分析,含缓存时间duration的在代码中改变的自己实现的机制
当应用进程创建 RxCache 的实例后,会给应用进程返回一个 rxcache实例及一个 ProxyProvider,代码如下: CacheProviders providers = new RxCa ...
- mysql基础知识(5)--视图
视图 单词:view 什么是视图: 视图可以看作是一个“临时存储的数据所构成的表”(非真实表),其实本质上只是一个select语句.只是将该select语句(通常比较复杂)进行一个“包装”,并设定了一 ...
- 【原】Hadoop伪分布模式的安装
Hadoop伪分布模式的安装 [环境参数] (1)Host OS:Win7 64bit (2)IDE:Eclipse Version: Luna Service Release 2 (4.4.2) ( ...
- 2d网络游戏的延迟补偿(Lag compensation with networked 2D games)
http://gamedev.stackexchange.com/questions/6645/lag-compensation-with-networked-2d-games ——————————— ...