1

I'm having a problem figuring out how to make two equal columns (won't be exactly equal if the array length is odd) out of a single array.

So , and have them in two columns.

Norm Strassner
  • 225
  • 3
  • 11
  • If you can give an example of what you want to do, it will be easier for folks to help. You can clone this to create it https://stackblitz.com/edit/aurelia-javascript?file=index.js – bigopon Sep 21 '18 at 22:56

1 Answers1

2

This isn't really a question specific to Aurelia, but I'm guessing the follow-up question would be.

won't be exactly equal if the array length is odd

That tells me you want to have this:

[1, 2, 3, 4, 5, 6]

And turn it into this:

[[1, 2], [3, 4], [5, 6]]

If you want to do this in a repeater, try this:

export class PairValueConverter {
    fromView(input) {
        return input.reduce((res, cur, i, arr) {
          if (i % 2 === 0) res.push(arr.slice(i, i + 2));
          return res;
        }, []);
    }
}

And then in your html:

<div repeat.for="item of items | pair">${item[0]} - ${item[1]}</div>

It's better if you put more effort in your question though, show what you've tried, etc. Someone might judge me for answering this :)

Fred Kleuver
  • 7,797
  • 2
  • 27
  • 38