UNPKG

pragmatic-fp-ts

Version:

Opinionated functional programming library with easy use in mind

29 lines (28 loc) 938 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.endsWith = void 0; const main_1 = require("./main"); function endsWith(tail, seq) { if (arguments.length === 1) { return (theSeq) => endsWith(tail, theSeq); } const _tail = (0, main_1.getValue)(tail); const _seq = (0, main_1.getValue)(seq); if ((0, main_1.isNil)(_tail) || (0, main_1.isNil)(_seq)) return false; if (typeof _tail === "string" && typeof _seq === "string") { return _seq.endsWith(_tail); } else if (_tail instanceof Array && !(_seq[0] instanceof Array)) { let j = _seq.length - 1; for (let i = _tail.length - 1; i > 0; --i, --j) { if (!(0, main_1.equals)(_tail[i], _seq[j])) return false; } return true; } else { return (0, main_1.equals)(_seq[_seq.length - 1], _tail); } } exports.endsWith = endsWith;