Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
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
Dakota Brown
@da-code-a
Hi all! I'm learning Sibilant right now and I'm not seeing in the docs how to put a value into an array? I see that there's an append, but it was deprecated. Forgive me for silly questions, I've never used a LISP before.
Dakota Brown
@da-code-a
Alright, I can append to the list, but the output isn't what I expected... When I append an object's property to the list, it adds it as ['property_value': undefined] rather than just ["property_value"]
I'm doing (set result (+ result object.property))
Dakota Brown
@da-code-a
@jbr Sorry for the ping, but is it possible to get some help?
Dakota Brown
@da-code-a
Got it, I need to do (assign result (+ result object.property)) instead.