Creator here! Let me know if you have any suggestions.
Although this is a case where idiomatic python is different from idiomatic js.
In js:
// same:
!! "" // false
!! 0 // false
!! 1 // true
!! null // false
// different:
!! {} // true
!! [] // true
while in python: # same:
not not "" # False
not not 0 # False
not not 1 # True
not not None # False
# different:
not not {} # False
not not [] # False
not not tuple() # FalsePerhabs just personal preference but I'd use
for(let element of someList){
console.log(element);
}
instead of someList.forEach(element => {
console.log(element)
})
for...of is easier to read and recognize as a loop construct at first glance, and as far as I recall it's also faster nowadays since the body of the loop is inline, whereas forEach requires the runtime to deal with a function object.Example:
var queryLondonCustomers = from cust in customers
where cust.City == "London"
select cust;
I'm not a big fan of it honestly, the function style seems more consistent and easier to read to me. for each(str from [list: "Ahoy", "world!"]):
print(str)
end
for map(n from [list: 1,2,3]): n * n end
# ==> [list: 1, 4, 9]
for filter(n from [list: 1, 2, 3]):
n >= 2
end
# ==> [list: 2, 3]
for fold(sum from 0, n from [list: 4, 5, 6]):
sum + n
end
# ==> 15 Object.entries(newDict).forEach(element => {
console.log(`${element[0]} ${element[1]}`)
})
... you could write ... for (const key in newDict) {
console.log(`${key} ${newDict[key]}`)
}
... or ... for (const [key, value] of Object.entries(newDict)) {
console.log(`${key} ${value}`)
}Second: I don't like seeing JavaScript code without semicolons. Maybe I am old, but it makes me nervous.