[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 ...
随机推荐
- jQuery文档加载完毕的几种写法
js中文档加载完毕.一般在body加一个onload事件或者window.onload = function () {} jQuery中有好多写法,平时也不注意,别人一问,还真觉得头大. 下面是我整理 ...
- [LeetCode] #167# Two Sum II : 数组/二分查找/双指针
一. 题目 1. Two Sum II Given an array of integers that is already sorted in ascending order, find two n ...
- 【Excel】Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046}:
[Excel]Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-0000000000 ...
- 转】Spark DataFrame小试牛刀
原博文出自于: https://segmentfault.com/a/1190000002614456 感谢! 三月中旬,Spark发布了最新的1.3.0版本,其中最重要的变化,便是DataFrame ...
- 一个效果很华丽的仿桌面APP,却胜似Launcher
开发Android APP的同学是否对于Launcher实现的绚丽效果而痴迷呢?什么,连Android Launcher是什么都不知道.好吧,拿起侬的手机,在解锁后的首页界面上左右滑动滑动,体验体验, ...
- SKAction
[SKAction] 1.Every action is an opaque object that describes a change you want to make to the scene. ...
- poj 3264 Balanced Lineup(RMQ裸题)
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 43168 Accepted: 20276 ...
- 解决 Unable to load DLL 'OraOps9.dll': 找不到指定的模块。 (Exception from HRESULT: 0x8007007E)
这个问题网上的答案是把oracle的home文件夹权限变为完全控制,然而并没有好用,还有一种方法是在编写的程序的config文件加入 <runtime> <legacyCorrupt ...
- Joel Spolsky对计算机学生的七大建议
/*先来介绍下作者:Joel Spolsky,世界最具影响的程序员网志Joel on Software的主人,软件业一位旗帜鲜明的思想者,一位传统软件管理理念的挑战者.他创办的这个网站被程序员誉为“反 ...
- iOS多线程总结
1.不要同时开太多的线程(1~3条线程即可,不要超过5条) 2.线程概念 1> 主线程 : UI线程,显示.刷新UI界面,处理UI控件的事件 2> 子线程 : 后台线程,异步线程 3.不要 ...