UNPKG

@thi.ng/transducers

Version:

Collection of ~170 lightweight, composable transducers, reducers, generators, iterators for functional data transformations

13 lines (12 loc) 427 B
import { isArray } from "@thi.ng/checks/is-array"; import { isString } from "@thi.ng/checks/is-string"; import { concat } from "./concat.js"; import { reverse } from "./reverse.js"; import { str } from "./str.js"; import { symmetric } from "./symmetric.js"; function palindrome(x) { return isString(x) ? str("", concat([x], reverse(x))) : isArray(x) ? x.concat(x.slice().reverse()) : symmetric(x); } export { palindrome };