How to use the last function from ramda

Find comprehensive JavaScript ramda.last code examples handpicked from public code repositorys.

ramda.last returns the last element of an array.

107
108
109
110
111
112
113
114
115
116
    obj
  )

const clone = (obj) => JSON.parse(JSON.stringify(obj))

const key = (r) => R.last(R.keys(r))

const valueForKey = (v) => v[key(v)]

const returnArray = (prop) => R.pathOr([], [prop])
fork icon3
star icon44
watch icon6

604
605
606
607
608
609
610
611
612
613
this._initialSyncPeers = this._initialSyncPeers.filter(syncPeer => syncPeer.host !== peer.host);
if (peerSegments[peer.host]) {
  delete peerSegments[peer.host];
}
const [firstHash] = this._requestedBlockHashes;
const lastHash = last(this._requestedBlockHashes);
if (!lastHash) {
  this._logger.debug('Request headers array was empty and should not be');
}
// const peerMessage = new Messages().GetBlocks({ starts: [firstHash], stop: lastHash })
fork icon12
star icon5
watch icon7

+ 2 other calls in file

How does ramda.last work?

ramda.last is a function that takes an array as its argument and returns the last element of the array. It does not modify the original array. If the input array is empty, it returns undefined.

3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
'pop': {
    dt: '[[[A+]][[Ab] Al] bind]',
    compose: function (s) {
        var arr = toArrOrNull(s === null || s === void 0 ? void 0 : s.pop());
        if (arr) {
            s.push(r.init(arr), r.last(arr));
        }
        return [s];
    }
},
fork icon0
star icon5
watch icon0

+ 4 other calls in file

173
174
175
176
177
178
179
180
181
182
183
184
    return data;
};


const deleteEntity = R.curry(async (changeDependency, entityToDelete) => {
    const data = R.compose(getEntity, R.head)(entityToDelete);
    const entity = R.last(entityToDelete);
    return deleteAssociatedEntities(entity, data, changeDependency);
});



fork icon4
star icon0
watch icon0

Ai Example

1
2
const myArray = [1, 2, 3];
const lastElement = R.last(myArray); // Returns 3

497
498
499
500
501
502
503
504
505
506
  strictEqual(R.isEmpty(enumValues({})), true)
})

it('should return the list of values of the enum type', function () {
  const m = extractValue(
    R.last(
      enumValues({
        kind: 'EnumTypeDefinition',
        name: {
          kind: 'Name',
fork icon3
star icon44
watch icon6

101
102
103
104
105
106
107
108
109
110
)

const generatedEnums = []
const generatedScalars = []
const entity = `${camelToSnakeCase(R.last(namespace.split('.')))}${version > 1 ? `_v${version}` : ''}`
const rootStruct = R.last(protoTypes).sort((a, b) => {
  const aDirectives = __directives(a)
  const bDirectives = __directives(b)
  if (parseInt(order(aDirectives[extractName(a)])) > parseInt(order(bDirectives[extractName(b)]))) {
    return 1
fork icon3
star icon44
watch icon6

51
52
53
54
55
56
57
58
59
60
getBlockByHash(hash) {
    return R.find(R.propEq('hash', hash), this.blocks);
}

getLastBlock() {
    return R.last(this.blocks);
}

getDifficulty(index) {        
    // Calculates the difficulty based on the index since the difficulty value increases every X blocks.
fork icon0
star icon1
watch icon0

6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
* @param {*} list
* @return {*}
* @see R.init, R.head, R.tail
* @example
*
*      R.last(['fi', 'fo', 'fum']); //=> 'fum'
*      R.last([]); //=> undefined
*
*      R.last('abc'); //=> 'c'
*      R.last(''); //=> ''
fork icon0
star icon0
watch icon0

+ 71 other calls in file

23
24
25
26
27
28
29
30
31
32
33
34
35


const batchLazyTasks = count => tasks => tasks.reduce((batches, task) => {
  if (batches.length === 0) return [[task]];


  const full = R.init(batches);
  const last = R.last(batches);


  if (last.length >= count) return [...batches, [task]];
  return [...full, [...last, task]];
}, []);
fork icon0
star icon0
watch icon0

+ 3 other calls in file

214
215
216
217
218
219
220
221
222
223
var getModifiedSource = function getModifiedSource(identifier) {
  var obj = parse(identifierToFilename(identifier));
  escodegen.attachComments(obj.ast, obj.comments, obj.tokens);
  abortIfEmptyBody(obj.ast);
  abortIfExportNotLast(obj.ast);
  var last = R.last(obj.ast.body);
  var declarationAst = {
    type: 'VariableDeclaration',
    kind: 'var',
    leadingComments: obj.comments,
fork icon0
star icon0
watch icon0

0
1
2
3
4
5
6
7
8
9
10
11
const data = require("./data.json")
const R = require("ramda")


const sortedAdapters = R.pipe(
  R.sort((a, b) => a - b),
  (arr) => [0, ...arr, R.last(arr) + 3]
)(data)


const countJoltageDiffs = R.pipe(
  R.aperture(2),
fork icon0
star icon0
watch icon0

82
83
84
85
86
87
88
89
90
91
  }

  // ------------PUBLIC INSTANCE METHODS -------------------

  getRollsToWin() {
      const winner = this.#players.find(player => R.last(player.getMoves()).endPosition === this.#boardSize);
const rollsToWinInGame = winner.getRolls().length;
console.log(`Winner ${winner.userId} needed ${rollsToWinInGame} rolls to win`)
return rollsToWinInGame;
  }
fork icon0
star icon0
watch icon0

21
22
23
24
25
26
27
28
29
30
    if (this.secret == null)
{
        this.generateSecret();
    }

    let lastKeyPair = R.last(this.keyPairs);

    // Generate next seed based on the first secret or a new secret from the last key pair.
    let seed = (lastKeyPair == null ?  this.secret : CryptoUtil.generateSecret(R.propOr(null, 'secretKey', lastKeyPair)));
    let keyPairRaw = CryptoUtil.generateKeyPairFromSecret(seed);
fork icon0
star icon0
watch icon0

8
9
10
11
12
13
14
15
16
17
18
19
20
// --------------------------------------------


function parse(lines) {
    const moves = [];


    const moves1 = R.last(lines).split('');
    let buf = [];


    for (let i = 0; i < moves1.length; i ++) {
        if (Number.isInteger(Number.parseInt(moves1[i]))) {
fork icon0
star icon0
watch icon0

86
87
88
89
90
91
92
93
94
95
            UserProfile_1.userProfile.UpdateBalance();
        }, 1000);
    });
};
RewardPopupsMgr.prototype.showPopup = function () {
    var item = R.last(this.rewardPopups);
    if (!item)
        return;
    this.rewardPopups = R.dropLast(1, this.rewardPopups);
    var _a = item.data, turn = _a.turn, coin = _a.coin, type = item.type;
fork icon0
star icon0
watch icon0

31
32
33
34
35
36
37
38
39
40
if (isEmpty(selection)) {
  // no coins to select
  return { fee: 0, inputs: [], outputs: [] };
} else {
  let maxBalance = last(selection)[0];
  let fee = last(selection)[1];
  let selectedCoins = map(e => e[2], selection);
  if (maxBalance < target + fee) {
    // not enough money to satisfy target
    return { fee: fee, inputs: [], outputs: targets };
fork icon0
star icon0
watch icon0

+ 3 other calls in file

18
19
20
21
22
23
24
25
26
27
const dispatch = useDispatch()
const classes = useStyles();
const url = getOrigin()
const api_key = getApiKey()
const handleDownloadReportLink = () => {
  const docId = audit.field_audit_document ? R.last(audit.field_audit_document.split("/")).split(".")[0] : null
  if (!docId) {
    return null
  }
  return `${url}/system/file-store/download/${docId}/`
fork icon0
star icon0
watch icon0

85
86
87
88
89
90
91
92
93
94
95
// allow differentiation between first iteration and subsequent iterations
// const bitrateAdder = (resultAccumulator, rungSpec) => kindof(resultAccumulator) === 'number' ?
//   [R.assoc('bitrate', resultAccumulator, rungSpec)] :
//   [...resultAccumulator, R.assoc(
//     'bitrate',
//     nextRungBitrate(R.last(resultAccumulator).bitrate, R.last(resultAccumulator).dim, rungSpec.dim, rungSpec.tuning),
//     rungSpec
//   )]


// bitrateDimMult :: RungSpec -> Number -> Number
fork icon0
star icon0
watch icon0

+ 3 other calls in file

36
37
38
39
40
41
42
43
44
45
    right: R.compose(maybeAsInt, R.prop(2)),
    op: R.prop(1)
  }),
  R.split(' '),
  R.trim(),
  R.last(),
  R.split('=')
)(operationData),
testValue: extractNumber(testData),
trueTarget: extractNumber(trueData),
fork icon0
star icon0
watch icon0

125
126
127
128
129
130
131
132
133
134
135


console.time("pt2")
console.log(
  "pt2",
  findWireAValue(
    commands.filter((cmd) => R.last(cmd) !== "b"),
    { b: 956 }
  )
)
console.timeEnd("pt2")
fork icon0
star icon0
watch icon0

Other functions in ramda

Sorted by popularity

function icon

ramda.clone is the most popular function in ramda (30311 examples)