[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 ...
随机推荐
- keyCode 与charCode
键盘事件拥有两个属性,keyCode和CharCode,他们之间有一些不一样之处.keyCode表示用户按下键的实际的编码,而charCode是指用户按下字符的编码. IE下 keyCode:对于ke ...
- SandDock 应用示例
直接上代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data ...
- junit4新框架hamcrest
Hamcrest是一个书写匹配器对象时允许直接定义匹配规则的框架.有大量的匹配器是侵入式的,例如UI验证或者数据过滤,但是匹配对象在书写灵活的测试是最常用.本教程将告诉你如何使用Hamcrest进行单 ...
- 《学习OpenCV》练习题第四章第一题a
#include <highgui.h> #include <cv.h> #pragma comment (lib,"opencv_calib3d231d.lib&q ...
- ruby 安装更新
wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz tar xfvz ruby-2.2.2.tar.gz cd ruby-2. ...
- Intel XDK问题
1.不能加入AndroidManifest.xml或者info.plist文件,没法设置特定信息,例如强制横屏. 2.不能自定义图表和启动loading界面
- Node-APN 开源推送服务
Node-APN是一个开放的结合了苹果推送通知的Node.js模块,该源码模块使用简单,反馈服务支持.错误处理,在发送出错时自动重发.遵从苹果的最佳实践. Node-APN(github)
- windows 无法启动asp.net 状态服务 错误 0x8007277a
处理方法:如果在启动ASP.NET State Service服务时遇到问题0x8007277a即无法启动或初始化,请尝试在命令行(CMD)中输入netsh winsock reset(有可能是wi ...
- UVALive 3956 Key Task (bfs+状态压缩)
Key Task 题目链接: http://acm.hust.edu.cn/vjudge/contest/129733#problem/D Description The Czech Technica ...
- c#读properties文件
@(编程) properties文件 MONGO_URL = mongodb://172.16.20.3/srtc_dc CURRENT_VERSION = 2.0 IS_AUTO_UPDATE = ...