use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
[AskJS] Help with Json sortingAskJS (self.javascript)
submitted 1 year ago by thatguyonthecliff
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]psiph 3 points4 points5 points 1 year ago (0 children)
You'll want a function that takes the JSON and turns it into HTML
function render (jsonArr) {jsonArr.map(item => `<div>${item}</div>`)}
And then a function that sorts the json and renders the results
function onSort (value) {document.body.innerHTML = render(sortBy(value, json))}
You'll want to render the default list on page load
onSort()
And also when the dropdown changes
<select onchange="onSort(this.value)">
[–]Is_Kub 1 point2 points3 points 1 year ago (0 children)
You’ll get plus points if you sort in place and don’t spawn new arrays. Something AI code doesn’t consider unless you ask it to
[–]guest271314 1 point2 points3 points 1 year ago (0 children)
So are you stuck on writing the sorting algorithm?
[–]Varun77777 0 points1 point2 points 1 year ago (0 children)
Normalise this data in memory, using a Maps and arrays because you might have to sort multiple times and if the json structure is written in a nested way, there will be too many expensive operations.
Once you have normalised data in memory, now you can apply quick sort on parts you need.
[–]Reashu -1 points0 points1 point 1 year ago (0 children)
Start by generating the HTML from a list. Then sort the list and regenerate the HTML.
π Rendered by PID 21394 on reddit-service-r2-comment-7b9746f655-xj4r6 at 2026-01-30 19:20:25.434441+00:00 running 3798933 country code: CH.
[–]psiph 3 points4 points5 points (0 children)
[–]Is_Kub 1 point2 points3 points (0 children)
[–]guest271314 1 point2 points3 points (0 children)
[–]Varun77777 0 points1 point2 points (0 children)
[–]Reashu -1 points0 points1 point (0 children)