Skip to content

Commit 433c754

Browse files
committed
Added halve module
1 parent 36fb1a2 commit 433c754

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const gcd = require('./src/gcd')
5757
const getNth = require('./src/get-nth')
5858
const gt = require('./src/gt')
5959
const gte = require('./src/gte')
60+
const halve = require('./src/halve.js')
6061
const hasProp = require('./src/has-prop')
6162
const head = require('./src/head')
6263
const id = require('./src/id')
@@ -250,6 +251,7 @@ module.exports = {
250251
getNth,
251252
gt,
252253
gte,
254+
halve,
253255
hasProp,
254256
head,
255257
id,

src/halve.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
2+
const and = require('./and')
3+
const curry = require('./curry')
4+
const div = require('./div')
5+
const len = require('./len')
6+
const notArr = require('./not-arr')
7+
const notStr = require('./not-str')
8+
const partitionAt = require('./partition-at')
9+
const trunc = require('./trunc')
10+
11+
function halve(xs) {
12+
if (and(notArr(xs), notStr(xs)))
13+
throw new TypeError('[halve] Argument must be an array or a string')
14+
15+
return partitionAt(trunc(div(len(xs), 2)), xs)
16+
}
17+
18+
module.exports = curry(halve)

0 commit comments

Comments
 (0)