Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
motivate
@motivate:matrix.org
[m]
and that too in descending order
Jacob Rothstein
@jbr
so return stringHash instead of (console.log stringHash)
objects in javascript are technically ordered but there is no way to sort them
it's best to treat them as unordered
if you need them to be sorted, you'll want to return something other than an object
motivate
@motivate:matrix.org
[m]
Yes I need to sort them
Can you help me with that
Jacob Rothstein
@jbr
i don't understand what you're trying to output
objects aren't sorted
i mean object keys are not reorderable. they're insert ordered
motivate
@motivate:matrix.org
[m]
I am getting this output:
{ hello: 2, hi: 3 }
Jacob Rothstein
@jbr
what's wrong with that?
motivate
@motivate:matrix.org
[m]
But I want my output to be hi:3, hello:2
Jacob Rothstein
@jbr
i mean what do you want the output to be?
that's not how objects work, it's like a hash or a map
motivate
@motivate:matrix.org
[m]
so should I change the whole code
?
Jacob Rothstein
@jbr
you can collect them to an array like [["hi", 3], ["hello", 2]]
5 replies
motivate
@motivate:matrix.org
[m]
Can you please tell me if I am having a list of strings So I want to print the disticnt strings out of that list with their respective counts
so how can I do it?
for keys I think I have to mention the count itself but I just have a list of strings in my output
input*
Jacob Rothstein
@jbr
Is this an assignment of some sort?
motivate
@motivate:matrix.org
[m]
yup
I am stuck at this point
Jacob Rothstein
@jbr
it might help to look at the output javascript and see what you'd want to do with that
motivate
@motivate:matrix.org
[m]
It is Like Input: {'hello 'hi 'hi 'hello 'hi} and then I want output as: {hi:3, hello:2}
Jacob Rothstein
@jbr
have you looked at the output javascript
motivate
@motivate:matrix.org
[m]
no
not yet
Jacob Rothstein
@jbr
that is the next step
it will help you understand what sibilant is actually doing
motivate
@motivate:matrix.org
[m]
```
It would be like this in javascript
Jacob Rothstein
@jbr
that doesn't return the results in any order
they're displayed in the order that they occur, not alphabetically
motivate
@motivate:matrix.org
[m]
It is just for count as keys and values and I want the order based on count i.e. descending- 3,2,1
Jacob Rothstein
@jbr
then you want an array output, not an object
the javascript above returns unordered results
motivate
@motivate:matrix.org
[m]
Yes I want an array output just the sorted counts
Jacob Rothstein
@jbr
take a look at Object.keys or sibilant's keys macro. you can map the keys to [[k, v], ...] and then sort that
motivate
@motivate:matrix.org
[m]
This is more general code in java script
Jacob Rothstein
@jbr
that's java not javascript
sibilant compiles to javascript
motivate
@motivate:matrix.org
[m]
Sorry I pasted the wrong code
Jacob Rothstein
@jbr
You should be able to translate that to sibilant. Let me know if you run into specific stumbling blocks
motivate
@motivate:matrix.org
[m]
okay sure
motivate
@motivate:matrix.org
[m]
Hi I tried this
but it is saying sort is not a function