Are list-comprehensions and functional functions faster than “for loops”?

In terms of performance in Python, is a list-comprehension, or functions like map(), filter() and reduce() faster than a for loop? Why, technically, they run in a C speed, while the for loop runs in the python virtual machine speed?. Suppose that in a game that I’m developing I need to draw complex and huge … Read more

JavaScript “new Array(n)” and “Array.prototype.map” weirdness

I’ve observed this in Firefox-3.5.7/Firebug-1.5.3 and Firefox-3.6.16/Firebug-1.6.2 When I fire up Firebug: var x = new Array(3) console.log(x) // [undefined, undefined, undefined] var y = [undefined, undefined, undefined] console.log(y) // [undefined, undefined, undefined] console.log( x.constructor == y.constructor) // true console.log( x.map(function() { return 0; }) ) // [undefined, undefined, undefined] console.log( y.map(function() { return 0; … Read more

map function for objects (instead of arrays)

I have an object: myObject = { ‘a’: 1, ‘b’: 2, ‘c’: 3 } I am looking for a native method, similar to Array.prototype.map that would be used as follows: newObject = myObject.map(function (value, label) { return value * value; }); // newObject is now { ‘a’: 1, ‘b’: 4, ‘c’: 9 } Does JavaScript … Read more