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的更多相关文章

  1. coffeescript 1.8.0 documents

    CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque ...

  2. coffeescript 1.6.3使用帮助

    CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque ...

  3. Tempo 2.0

    Tempo 2.0 Tempo is an easy, intuitive JavaScript rendering engine that enables you to craft data tem ...

  4. how to use coffee script

    TABLE OF CONTENTS TRY COFFEESCRIPT ANNOTATED SOURCE CoffeeScript is a little language that compiles ...

  5. mysql 5.7.17发布

    Mysql 5.7.17发布了,主要修复: Changes in MySQL 5.7.17 (2016-12-12, General Availability) Compilation Notes M ...

  6. 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 ...

  7. Zend API:深入 PHP 内核

    Introduction Those who know don't talk. Those who talk don't know. Sometimes, PHP "as is" ...

  8. iPhone Tutorials

    http://www.raywenderlich.com/tutorials This site contains a ton of fun written tutorials – so many t ...

  9. 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 ...

随机推荐

  1. 如何解决grails2.3.2中不能运行fork模式

    升级到grails 2.3.2之后,运行时报如下的异常: Exception in thread "main" Error | Forked Grails VM exited wi ...

  2. java中子类与基类变量间的赋值

    Java中子类与基类变量间的赋值 子类对象可以直接赋给基类变量. 基类对象要赋给子类对象变量,必须执行类型转换, 其语法是: 子类对象变量=(子类名)基类对象名; 也不能乱转换.如果类型转换失败Jav ...

  3. Spark connect to Database

    Cannect to Cassandra: 用spark-cassandra-connector, 注意spark,cassandra和connector的版本要配套,Cassandra至少要版本2以 ...

  4. wifi reaver

    PIN码的格式很简单, 八位十进制数,最后一位(第8位)为校验位(可根据前7位算出),验证时先检测前4位,如果一致则反馈一个信息,所以只需1万次就可完全扫描一遍前4位,前4位确定下来的话,只需再试10 ...

  5. Myeclipse2014 自带的报表功能 与 Eclipse BIRT

    Myeclipse2014 自带的报表功能跟 Eclipse BIRT 差不多,但不兼容   1.只能是MyEclipse Web projects 或者 Report Web project不支持B ...

  6. adb device出现error:unknown host service

    最近在windows下使用adb device时,提示“ADB server didn't ACK” & “error: unknown host service”错误. 网上搜索了下,是说a ...

  7. 给一已经排序数组A和x,求A中是否包含两个元素之和为x

    亲爱的大神老爷们,这是小渣第一次写blog,欢迎大家来喷(批评指正),算法渣因为面试中连这道题都不会写就自己琢磨了一下,也参考了网上大家的做法 解法一: 思路:从首尾向目的靠拢,因为已经排序,[假设存 ...

  8. 前端复习-02-ajax原生以及jq和跨域方面的应用。

    ajax这块我以前一直都是用现成的jq封装好的东西,而且并没有深入浅出的研究过,也没有使用过原生形式的实现.包括了解jsonp和跨域的相关概念但是依然没有实现过,其中有一个重要的原因我认为是我当时并不 ...

  9. HDU 2101 A + B Problem Too 分类: ACM 2015-06-16 23:57 18人阅读 评论(0) 收藏

    A + B Problem Too Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  10. Ubuntu之系统交换分区Swap增加与优化

    http://os.51cto.com/art/201212/372860.htm   http://blog.csdn.net/xingyu15/article/details/5570225   ...