The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Sorting input, Need help figuring out sorting input values
Tirans
post 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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Dec 3 2020, 01:37 PM
Post #2


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(Tirans @ Dec 3 2020, 05:41 PM) *

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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 05:02 PM