Skip to main content

Write python using js syntax

Project description

jssyntax

Write python using js syntax

Installation

pip install jssyntax

Usage

from jssyntax import List

numbers = List([1, 2, 3, 4, 5])

#forEach
list = []
numbers.forEach(lambda item, index, array: 
    #使用元祖来确保两个handle都在lambda表达式中
    (print(f"Item: {item}, Index: {index}, Array: {array}"),
        list.append(item))
)
print(list)


# 调用 map 方法
squared_numbers = numbers.map(lambda item, index, array: item ** 2)
print(squared_numbers)


even_index = numbers.findIndex(lambda item, index, array: item % 2 == 0)
print(f"第一个偶数的位置是: {even_index}")


# 使用 splice 方法
removed_elements = numbers.splice(1, 2, 10, 20)
print(f"删除的元素: {removed_elements}")
print(f"修改后的列表: {numbers}")


# 调用 filter 方法
filtered_numbers = numbers.filter(lambda item, index, array: item % 2 == 0)
print(f"过滤后的列表: {filtered_numbers}")

#push和pop
numbers.push(100)
print(numbers)
numbers.pop()
print(numbers)


# 调用 reduce 方法
sum_of_numbers = numbers.reduce(lambda acc, item, index, array: acc + item, 0)
print(f"所有数字的和是: {sum_of_numbers}")

#flatmap 
print(numbers.join(","))
print(numbers.flatMap(lambda item: [item, item * 2]))

#includes
print(numbers.includes(100))
print(numbers.includes(1000))


PS:

# 清理旧的构建文件
rm -rf dist/ build/ jssyntax.egg-info/

# 重新构建
python setup.py sdist bdist_wheel

# 上传到 PyPI
twine upload dist/* --verbose


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jssyntax-0.2.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jssyntax-0.2.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file jssyntax-0.2.1.tar.gz.

File metadata

  • Download URL: jssyntax-0.2.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for jssyntax-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9b10b69d6fbf82307a8112274c30126c8a45ee9f5b6fdf538bad14c55f6d6308
MD5 45eb85ef6f5bcd22234d3253bf0ae1ba
BLAKE2b-256 f4b4dde6f2c15863b7c29c0009b973434e017e5a56f51c8cbcc28f0d8b031c5d

See more details on using hashes here.

File details

Details for the file jssyntax-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: jssyntax-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for jssyntax-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ff450cd6b0025c701c069499b2f4d2624d7a4f6c777d8b410cf813bf9cffccf0
MD5 0969d0e50705c2485fc4b08d8117817f
BLAKE2b-256 dcedd30ae2cf909fffaabf30931912efb783181c6bd01fd338e053fbf90f82f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page