0

join function to get an ordered output

Hi to all

i have a formula:

let data := text(response.result.relations);
let bandData := parseJSON(data);
let artists := "";
for i in bandData do
    let artistType := i.type;
    if artistType = "member of band" then
        let artistName := i.artist.name;
        let artistAttributes := "";
        for attr in i.attributes do
            artistAttributes := artistAttributes + ", " + attr
        end;
        if artistAttributes != "" then
            artists := artists + artistName + " (" + artistAttributes + ")" + ", "
        else
            artists := artists + artistName
        end
    end
end;
Band := artists

which is giving me this output:

 

Syd Barrett (, guitar, lead vocals), Richard Wright (, keyboard, lead vocals), Roger Waters (, bass guitar, lead vocals), Nick Mason (, drums (drum set), percussion), David Gilmour (, guitar, lead vocals, slide guitar), Richard Wright (, keyboard, lead vocals), 

 

I would like to have this output if possible:

 

Syd Barrett ( guitar, lead vocals)

Richard Wright (keyboard, lead vocals)

Roger Waters (, bass guitar, lead vocals)

Nick Mason (drums (drum set), percussion)

David Gilmour (guitar, lead vocals, slide guitar)

 

Thanks to all of you

4 replies

null
    • szormpas
    • 10 mths ago
    • Reported - view

    Have you tried the join function with a line break separator? Something like:

    join('Band', "
    ")
    
      • francescostefanello
      • 10 mths ago
      • Reported - view

       

      • Sean
      • 10 mths ago
      • Reported - view

       I think you would need to use join() on Band after artists has been assigned to it. Why not just use join() on artists?

    • francescostefanello
    • 10 mths ago
    • Reported - view

    I finally came to this:

     

    let data := text(response.result.relations);
    let bandData := parseJSON(data);
    let xbanddata := join(for p in bandData do
            let beginDate := item(p, "begin");
            let endDate := item(p, "end");
            if p.type = "member of band" then
                if beginDate = null and endDate = null then
    p.artist.name + ""
                else
                    if endDate = null then
    p.artist.name + " (from " + p.begin + " to present)"
                    else
    p.artist.name + " (from " + p.begin + " to " + endDate + ")"
                    end
                end
            else
                ""
            end
        end, "
    ");
    Band := trim(xbanddata)

     

    output:

    Syd Barrett (from 1965 to 1968-04)
    Richard Wright (from 1965 to 1981)
    Roger Waters (from 1965 to 1985)
    Nick Mason (from 1965 to present)
    David Gilmour (from 1968-02-18 to present)
    Richard Wright (from 1987 to 2008-09-15)

     

    the instruments are not present but the output is clean as I wanted 

Content aside

  • 10 mths agoLast active
  • 4Replies
  • 74Views
  • 3 Following