词汇:array
n. 衣服;排列,列阵;大批,一系列;[计]数组,阵列
相关场景
- Grace lowers the bio-sensor array over Jake's chest.>> 阿凡达 Avatar Movie Script
- Jake lies back, lowering the sensor array over his body.>> 阿凡达 Avatar Movie Script
- 19. reduce方法折叠集合:
- Enumerable模块的类,可对集合进行过滤,遍历和转化。map和select;还有个可以管理一切的方法 reduce(or inject), reduce可以转换结构;接受者,每个元素被调用一次,并产生返回值,累加器。 enum.reduce(0){|accumulator, element| accumulator + element} 0初始值;建议你总是使用一个带有起始值的累加器。 enum.reduce(0, :+);
数组转成Hash; array.reduce({}) {|hash, element| hash.update(element => true)}
users.select{|u| u.age>=21}.map(&:name) 获取大于等于21的names数组。比较低效;
User.reduce([]) {|names, user| names << user.name if user.age >=21 ; names}>> Effective Ruby- 18. 标准库里面的Set:
- Array#include? 的时间复杂度是O(n),数量变多,时间就边长。Hash#include? O(log n); Hash[permissions.map{|p|} [p,true]]; require('set'); @permissions= Set.new(permissions) ; Set是一个无序容器。有序容器SortedSet类。如果不需要顺序,又存在很多条记录要判断是否Include?(x),那么Set是最好的选择。>> Effective Ruby
- 17.数组参数:
- initialize(toppings) {Array(toppings}.each do |topping| ...} 转换为Array让代码更加健康。>> Effective Ruby
- 13. <=> 对象的排序:
- Version attr_reader(:major, :minor, :patch); version.split('.')map(&:to_i); Array#detect{}...;>> Effective Ruby
- 12. == 等价has 4个部分的检查:
- "foo" == "foo" => true; "foo".equal?("foo") => false; == 会做隐式转换。 1== 1.0 => true; ;equal? 意味着 object_id (同一个内存块); case表达式使用 ===; Regexp 类定义了=== ,所以 /er/ === "Her" is true, but "Her" === /er/ is false; [1,2,3].is_a(Array) true; [1,2,3] === Array => false; Array === [1,2,3] => true; === 接受者=== 参数 means 参数.is_a?(接受者);>> Effective Ruby
- 11.namespace:
- 定义类和打开修改类是一种写法,ruby里的类是可以修改的。命名空间是一种保证常量唯一性的方式。module Notebooks; sytle= Notebooks::Binding.new; ::Array 和 Cluster::Array 是不同的;Object::Array === ::Array; 命名空间就是为了程序之间的和平相处。>> Effective Ruby
- 2.nil:
- 所有对象的value都可能为nil;都来之 BasicObject. 一个类的对象被另外一个类的对象替换(多态)鸭子类型duck typing. 接口高于类型。 is_a? or respond_to? NomethodError; 任何对象都可能是nil,做好防范。可以将nil.to_s to_i; Array#compact 可以去除nil元素;>> Effective Ruby
- Our Academy offers a diverse array of lesson types scheduled throughout the week, at various times around the clock, providing you with the flexibility to attend as many sessions as you desire.
我们的学院提供一周中不同时间安排的各种课程类型,让您可以灵活地参加任意数量的课程。>> 2024-10 The metamorphosis from anxious wife- [Bruce opens his eyes and sees the Sanctuary II up in the sky and a single missile heading towards the base blowing away Scott away. Then a continuous array of missiles destroys the base completely and everyone sinks below to the underground.] [The camera pans over to see Bruce holding up tons of debris from collapsing on top of the other Avengers with his one good arm. Some debris is stuck on top of Rocket.]>> Avengers: Endgame 复仇者联盟4:终局之战 Movie Script
- She pushes the door open even further, revealing a vast array of breakers and switches inside.>> 侏罗纪公园 1 Jurassic Park (1993) Movie Script
- Muldoon CLANGS open a steel cabinet, revealing an impressive array of weaponry inside. He removes a shotgun and what looks like a small rocket launcher. He shoves a shell into the barrel of the rocket launcher, which accepts it with a faint electronic SIZZLE.>> 侏罗纪公园 1 Jurassic Park (1993) Movie Script
- As the group walks down the ramp and onto the floor, they begin to absorb the incredible array of technology: enormous cryonic freezer, their plug pulled years ago; empty incubators; tanks of formaldehyde with dinosaur fetuses and body parts.>> 侏罗纪公园3 Jurassic Park 3 (2001) Movie Script
- 70 INT. ACCESSION COUNCIL CHAMBER - CONTINUOUS 70 Bertie walks to the podium like a man to the gallows faced with an array of the Privy Councillors, members of the House of Lords, the Lord Mayor of the City of London, the Aldermen of the City of London and the High Commissioners of the Commonwealth countries.>> 国王的演讲 The King's Speech Movie Script
- FELIX:
- We're using portables to keepproduction going, but they don'tsupply enough power to the heatlamps, and we have to dry a lotof... 'coffee beans.' 183 ANOTHER ANGLE 183 They're now walking between the two rows of sheds, whereportable gas GENERATORS THRUM, and... Gordy can see long, wide platforms inside. Above the platforms are multiple arrays of powerful heat lamps.>> 间接伤害 Collateral Damage Movie Script
- Before him on the table is an array of SMALL TOOLS.>> 终结者The Terminator Movie Script
- [Sobs] We have hit their scanner arrays!>> 巴比伦5:开端 Babylon 5: In the Beginning Movie Script
- FIRST OFFICER: Alien scanner arrays interfering with our electrical systems.>> 巴比伦5:开端 Babylon 5: In the Beginning Movie Script
- And in order to reach the Space Station, we will work with a growing array of private companies competing to make getting to space easier and more affordable.>> 火星一代 The Mars Generation Movie Script
- They have to turn on the communications array, set up the solar panels, set up all of the ECLSS systems, and also set up a greenhouse because somebody might want to eat up there.>> 火星一代 The Mars Generation Movie Script
- We're using an array of three hydrophones to test his echolocation and hearing abilities.>> Free Willy: Escape from Pirate's Cove Movie Script
- He pauses at a pawnshop window. An array of handguns.>> 肖申克的救赎Shawshank Redemption Movie Script