Code Benchmark: QCObjects similarities to Python 3 using JavaScript

Code Benchmark: QCObjects similarities to Python 3 using JavaScript

List Comprehensions (Python vs QCObjects / JavaScript)

List Comprehensions are a language feature that is commonly associated with Python Data Structures.

A list comprehension in Python consists of brackets containing an expression followed by a for clause, then zero or more for or if clauses. This is a powerful feature of this language that was difficult to emulate in a modern language like JavaScript until QCObjects. Here is an example of how you can make more with less code using QCObjects to get the same behavioural results as you've done it coding on python.

1) Make a list that has only even numbers

For Python 3:

Python3> print ([index for index in range (9) if index % 2 == 0])
// result:
[0, 2, 4, 6, 8]

For QCObjects:

QCObjects> console.log ( range(9).filter ( index => index % 2 == 0 ) )
// result: 
[0, 2, 4, 6, 8]

2) Make a list from a string that says "human", so every element in the list is a character of the string.

For Python 3:

Python3> print ( list ( map (lambda x: x, 'human') )  )
// result:
['h', 'u', 'm', 'a', 'n']

For QCObjects:

QCObjects> console.log ( "human".list().map( x=>x ) )
// result:
['h', 'u', 'm', 'a', 'n']

3) Make a list where every element is the square of the index value.

For Python 3:

Python3> squares = [x**2 for x in range(10)]
// content of squares:
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

For QCObjects:

QCObjects> let squares = range(0,9).map(x => x**2)
// content of squares:
[
    0, 1, 4, 9, 16, 
  25, 36, 49, 64, 81
]

To run the examples above described you can run python3 command shell and qcobjects-collab shell respectively