34
loading...
This website collects cookies to deliver better user experience
npm install jspython-interpreter
jsPython()
.evaluate('print("Hello World!")')
.then(
r => console.log("Result => ", r),
e => console.log("Error => ", error)
)
jspython --file=path/to/jspython/file --param1=value --param
# initial array
nums = [1, 2]
"""
You can use all standard JavaScript functions
(https://www.w3schools.com/jsref/jsref_obj_array.asp).
"""
# add more numbers
for i in range(3,10):
nums.push(i)
# `filter` will leave only odd numbers
# `map` will create an object
# y will be an array of objects transformed from odd numbers
y = nums
.filter(n => n % 2)
.map((n, i) =>
newItem = {
index: i,
element: n,
square: Math.pow(n, 2),
cube: Math.pow(n, 3)
}
return newItem
)
print('Prints to console =>', y)
# last statement will be a result
return y