Tag Archives: Arrays

Find the median of two sorted arrays


via Find the median of two sorted arrays – Growing with the Web.

Let’s start with the trivial case, this problem could easily be solved by merging the two arrays into a single array. Merging can use the merge portion ofmerge sort which runs in O(n)O(n) time, and then the median could be retrieved by grabbing the middle element(s) in O(1)O(1) time. But is it possible to get the median using a sub-linear solution?

Arrays, Linked Lists and Performance


via Arrays, Linked Lists and Performance | Airspeed Velocity.

I was surprised at how surprising some found this. Quite a few people suggested the reduce version could be changed to not do the array copy (I don’t think it can). Some suggested maybe + could be optimized so it doesn’t perform a copy (I don’t think that it could easily, as we’ll see shortly).1

In other feedback, a few commented on the previous post about linked lists. Why implement an outdated data structure? What’s the point when we have arrays?

Video: Loops, Arrays and Objects in CoffeeScript – Methods & Two-dimensional Arrays


Lesson 13 of the CoffeeScript foundations course
Stage: Loops, Arrays and Objects

In this lesson we’ll talk about some useful methods for Arrays and also we’ll talk about Two-dimensional arrays and how to work with them, we also have a #CoffeeChallenge and #CoffeeQuiz!

Once you solve the challenge or the quiz of this lesson drop us a line on twitter with the #CoffeeChallenge and #CoffeeQuiz hashtag!

VER VERSIÓN EN ESPAÑOL: http://bit.ly/1K1j98z

Blog post of the video at railskarate.com: http://bit.ly/1M1RLM6
Take the Ruby Quiz: http://bit.ly/1IlxVGX

Follow us on Twitter: https://twitter.com/BastianVelandia
Follow Rails Karate: https://twitter.com/railskarate
Follow us on facebook: https://www.facebook.com/railskarate

And of course subscribe if you want us to upload more videos.
Thanks for your support!

Typed Arrays: Binary Data in the Browser


via Typed Arrays: Binary Data in the Browser – HTML5 Rocks.

Typed Arrays are a relatively recent addition to browsers, born out of the need to have an efficient way to handle binary data in WebGL. A Typed Array is a slab of memory with a typed view into it, much like how arrays work in C. Because a Typed Array is backed by raw memory, the JavaScript engine can pass the memory directly to native libraries without having to painstakingly convert the data to a native representation. As a result, typed arrays perform a lot better than JavaScript arrays for passing data to WebGL and other APIs dealing with binary data.

Typed array views act like single-type arrays to a segment of an ArrayBuffer. There are views for all the usual numeric types, with self-descriptive names like Float32Array, Float64Array, Int32Array and Uint8Array. There’s also a special view which has replaced the pixel array type in Canvas’s ImageData: Uint8ClampedArray.

DataView is the second type of view and it is meant for handling heterogeneous data. Instead of having an array-like API, the DataView object provides you a get/set API to read and write arbitrary data types at arbitrary byte offsets. DataView works great for reading and writing file headers and other such struct-like data.

Boiling Down Arrays with Array reduce


via Boiling Down Arrays with Array#reduce – A Drip of JavaScript.

We’ve talked before about the advantages of using Array‘s higher order functions (like mapand sort) rather than manually iterating over an array’s contents. But unlike map and sort, which produce new arrays, reduce can boil an array down to a new value of any type.

Consider the case of a library system which needs to show potential donors its effectiveness at spreading knowledge. In order to do that, it must determine how many book-checkouts there were last year. (Not total of all checkouts, since a single checkout may be for more than one book.)

Let’s get those Javascript Arrays to work fast


via Let’s get those Javascript Arrays to work fast | gamealchemist.

The array object is indeed very powerful, but you need to handle it with care since some quite innocent feature can be have a high time and/or garbage creation cost.

I’ll show here a few simple techniques that avoids those costs.
The performance benefits can be very high (more than 10X) for some features, so all this is worth a look.

WhitePaper: JavaScript Functions, Objects, and Arrays Chapter 15


 JS Functions, Objects, and Arrays Chapter 15

Contents

  • Definitions
  • Objects in JavaScript
  • A Sample Class
  • Object Life Cycle
  • Arrays
  • Control Structures
  • Definite Loops (for)