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]
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
Jacob Rothstein
@jbr
Sort is for arrays. You have an object. You need to use Object.keys and Array.prototype.map to turn the object into an array
motivate
@motivate:matrix.org
[m]
Can you help me with this how to convert it to array?
Jacob Rothstein
@jbr
Oh you can use Object.entries now, I forgot about that
So use sort on the entries of that object
Ha Nguyen
@iamha1
Hi team! I was given a task on sibilant, and I have such difficulty learning it. Would any of you be able to help me?
Jacob Rothstein
@jbr
@iamha1 there’s a good chance it’s the same task other folks have been looking for help with, so scrolling up will likely yield answers. If you still have specific questions, ask away
Ha Nguyen
@iamha1
@jbr Thank you so much! Let me do that!
Ha Nguyen
@iamha1

Guys, would you be able to help me how to sort a key-value pair. For example:

;1 declare tasks

(var tasks { 2 “eat breakfast”, 3 “go to work”, 1 "get up” })

;2 sort each task

tasks.sort [2 3 1] (# (a b) (- a b)))

how would you do it in javascript?
Ha Nguyen
@iamha1

@jbr var tasks = [
{id: 2 , name: “eat-breakfast”},
{id: 3, name: “go to work”},
{id: 1, name: “get up”}

];

tasks.sort(function (a-b){
return a.id - b.id;
});

This is how i would do in JS.
(I don't think I need a loop, right?! Because if do, I guess I need to create a new object to push the sorted values to). Thank you so much for being patient with me.
Jacob Rothstein
@jbr
 (var tasks [
    {id: 2, name: "eat-breakfast"},
    {id: 3, name: "go to work"},
    {id: 1, name: "get up"}])

(tasks.sort (#(a b) (- a.id b.id)))
that would be the identical code in sibilant — if you paste it into the "try sibilant into your browser" link at the top of docs.sibilant.org, the output is
var tasks = [ {
  id: 2,
  name: "eat-breakfast"
}, {
  id: 3,
  name: "go to work"
}, {
  id: 1,
  name: "get up"
} ];
tasks.sort((function(a, b) {
  /* eval.sibilant:6:12 */

  return (a.id - b.id);
}));
it's equivalent to do
(.sort tasks (#(a b) (- a.id b.id)))
Ha Nguyen
@iamha1
@jbr Thank you so much for helping me! I really appreciate you! :)
Franklin Shih
@fshih1
hello nice to meet everyone here
Jacob Rothstein
@jbr
👋
Franklin Shih
@fshih1
How could i convert a object to an array of tuples ?
or is there any documentation i could refer to?
i just saw your comment above, it says " You need to use Object.keys and Array.prototype.map to turn the object into an array"
I think i will try it out first