r/reactjs • u/swyx • Jul 01 '18
Help Beginner's Thread / Easy Question (July 2018)
Hello! just helping out /u/acemarke to post a beginner's thread for July! we had almost 550 Q's and A's in last month's thread! That's 100% month on month growth! we should raise venture capital! /s
Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! We’re a friendly bunch. No question is too simple. You are guaranteed a response here!
New to React? Free, quality resources here
Read the new, official Getting Started page on the docs
/u/acemarke's suggested resources for learning React and his React/Redux links list.
Want Help on Code?
Improve your chances of getting helped by putting a minimal example on to either JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new). Describe what you want it to do, and things you've tried. Don't just post big blocks of code.
If you got helped, pay it forward! Answer questions even if there is already an answer - multiple perspectives can be very helpful to beginners. Also there's no quicker way to learn than being wrong on the Internet.
1
u/galshii Jul 28 '18
Issue
Hello, Thanks ahead for anyone willing to help me, I have a problem with sorting an object array in js.
In this component I have a method that gets a day which is an array of [String,String] Objects.
My issue is when I try to sort the hours
array the function won't sort by my logics and understanding of this comparator and the array stays same even if the sort expression is false
.
Which can be found under sortHoursByTime declaration.
Expected Behavior
if (obj1.toTime < obj2.fromTime) then sort the array where obj1 is first in order.
For example: singular object in the array [fromTime,toTime] which after sort should be like this:
[ [ "8:30", "9:30"], ["11:00","13:00"] ]
Code:
Environment