← Back to challenges

Bell Number

JavaScriptHardloopsmath

Instructions

The Bell number is the number of ways an array of n items can be partitioned into non-empty subarrays.

Create a function that takes a number n and returns the corresponding Bell number.

Examples

bell(1) ➞ 1
// sampleArr = [1]
// possiblePartitions = [[[1]]]

bell(2) ➞ 2
// sampleArr = [1, 2]
// possiblePartitions = [[[1, 2]], [[1], [2]]]

bell(3) ➞ 5
// sampleArr = [1, 2, 3]
// possiblePartitions = [[[1, 2, 3]], [[1, 2], [3]], [[1], [2, 3]], [[1, 3], [2]], [[1], [2], [3]]]

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.