Using Ramda, and pointfree style, how can I copy the first item of an array to the end of it?

后端 未结 2 1469
一个人的身影
一个人的身影 2021-01-25 01:27

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          


        
相关标签:
2条回答
  • 2021-01-25 01:39

    The S combinator is useful here:

    S.S(S.C(R.append), R.head, [1, 2, 3]);
    // => [1, 2, 3, 1]
    
    0 讨论(0)
  • 2021-01-25 02:00

    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]
    
    0 讨论(0)
提交回复
热议问题