typescript - Generating Unique Codes Not Including All Words (Angular + TS) - Stack Overflow

I have the following:.tsWhere I am trying to generate a code based on an input. For my example above

I have the following:

.ts

Where I am trying to generate a code based on an input. For my example above I have:

input: Project Tracker Tool & Category Beta (BET)

output: PROTTERTBET and POCTERTOBET and so on...

(it ends with the same category depending on the input category)

But I have the issue where ideally I want the code to be more meaningful because my code only slices the first 8 characters which means for the word "Tool", none of its characters are included in the final output. My desired output is:

  • At least 1 character at minimum from each word is included.

  • It maintains the ordering of the characters so no randomization of selected characters

  • For longer inputs ideally all max out 8 characters, can vary e.g. selects 3 characters from first word, 3 from second, 2 from 3rd and so on. By this I mean the itemName maxes at 8 not the entire output.

  • Will also have smaller inputs e.g. "Tool" where it will maybe just use the entire word.

  • 6 character words MyItem maybe MyItem or MYITM.

  • Should generate new outputs (chances of the having same output is fine).

Project Tracker Tool examples should output PRJTRTOL or PJCTTKTL

I have the following:

https://stackblitz/edit/stackblitz-starters-ujlmy6?file=src%2Fmain.ts

Where I am trying to generate a code based on an input. For my example above I have:

input: Project Tracker Tool & Category Beta (BET)

output: PROTTERTBET and POCTERTOBET and so on...

(it ends with the same category depending on the input category)

But I have the issue where ideally I want the code to be more meaningful because my code only slices the first 8 characters which means for the word "Tool", none of its characters are included in the final output. My desired output is:

  • At least 1 character at minimum from each word is included.

  • It maintains the ordering of the characters so no randomization of selected characters

  • For longer inputs ideally all max out 8 characters, can vary e.g. selects 3 characters from first word, 3 from second, 2 from 3rd and so on. By this I mean the itemName maxes at 8 not the entire output.

  • Will also have smaller inputs e.g. "Tool" where it will maybe just use the entire word.

  • 6 character words MyItem maybe MyItem or MYITM.

  • Should generate new outputs (chances of the having same output is fine).

Project Tracker Tool examples should output PRJTRTOL or PJCTTKTL

Share Improve this question asked Nov 16, 2024 at 23:18 WickedWicked 1332 silver badges8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

From what I understand, the reference must be a maximum of 8 characters long. But does it have to be this length? If so, you'll need to take into account that you'll need to add one or more predefined characters to fill in if the item passed as a parameter is smaller than the minimum size.

Secondly, to answer your question, the human brain can recognize a word, especially by its first and last letters, and the content in the middle more or less resembles the complete word. For example, reading 'acheivement' when there's an error is relatively easy. It's also worth noting that the human brain is very good at reading without vowels, which it can reconstruct fairly well. If we take the word 'table' for example, it's quite easy to read with 'TBL'.

So, in terms of algorithm, I think it might be interesting to keep the first and last vowels of the word. Delete vowels (word by word), as long as the string is not smaller than the maximum size. If there are strictly more than 4 words in the input, you'll need to define a different algorithm (keep only the first of each word?). The same question arises if there are more than 8 words in the input (keep only the first letter of the first words?).

I'm sure we'll need more details on what you really want from your coding system. Once all this is defined, an algorithm will emerge naturally from your requirements.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745644727a4637900.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信