Skip to content Skip to sidebar Skip to footer

Using Ramda, And Pointfree Style, How Can I Copy The First Item Of An Array To The End Of It?

I want to take an array [1, 2, 3] and return [1, 2, 3, 1]. I'm using Ramda, and I can get the desired result like this: const fn = arr => R.append(R.prop(0, arr), arr); But I'd

Solution 1:

converge can be very helpful for things like this.

const rotate = R.converge(R.append, [R.head, R.identity])
rotate([1, 2, 3]); //=> [1, 2, 3, 1]

Solution 2:

The S combinator is useful here:

S.S(S.C(R.append), R.head, [1, 2, 3]);
// => [1, 2, 3, 1]

Post a Comment for "Using Ramda, And Pointfree Style, How Can I Copy The First Item Of An Array To The End Of It?"