Joining Words Into a Branch Name

The port of ticket_branch.py now has key and title from the first colon. Next comes the branch name: fix/ followed by the lowercased key and the title’s first six words, joined with hyphens. Python does it with split() and "-".join(), and JavaScript does both differently.

Split the Title Into Six Words

The Python helper cleans the title, splits it, and takes the first six words:

Language: Python
key = "PAY-2291"
title = "Refund emails show the wrong currency: EUR shown as USD"

words = title.lower().replace(":", "").split()
branch = f"fix/{key.lower()}-{'-'.join(words[:6])}"
print(f"Branch: {branch}")

The cleaning ports as .toLowerCase() and .replaceAll(). The split doesn’t. Python’s split() with no argument splits on runs of whitespace, but JavaScript’s .split() has no default separator, so with nothing to cut at, it returns the whole string as one piece:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.