Sorting input, Need help figuring out sorting input values |
Sorting input, Need help figuring out sorting input values |
Tirans |
Dec 3 2020, 11:41 AM
Post
#1
|
Group: Members Posts: 1 Joined: 3-December 20 Member No.: 27,668 |
Hello, i decided to learn HTML/javascript and i found an interesting task online which asks you to sort numbers
The idea of the task is i need to set up an input=text and then write in numbers 1-100 for example "1-10, 2, 5, 12, 5" and i need to sort them like this "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12" i need it to take in to count array and ignore symbols if there are any, but i cant figure out how can i do this under one input text. How shoul i go about this? |
Christian J |
Dec 3 2020, 01:37 PM
Post
#2
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
The idea of the task is i need to set up an input=text and then write in numbers 1-100 You mean let the user enter one number at the time? You could let the user press press a button that adds each new number to an array, and sorts it. Or you could let the user write a space-separated list of numbers into the text field at once, and let e.g. a javascript onkeyup event split the list into an array by the spaces, and then sort the array. You could also separate numbers by comma signs, but that could lead to confusion since commas are used differently in parts of the world. QUOTE ignore symbols if there are any Those can be stripped with a regular expression. |
Lo-Fi Version | Time is now: 23rd April 2024 - 01:53 AM |