Created
February 18, 2020 02:21
-
-
Save manobi/d963e070c86f2641ed209209077c1838 to your computer and use it in GitHub Desktop.
pure smallEnought version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* pure smallEnought version | |
* @param {array} a | |
* @param {number} limit | |
*/ | |
const smallEnought = ([head, ...tail], limit) => (!head && !tail.length) || ((head > limit) ? false : smallEnought(tail, limit)) |
Tests
const assert = require('assert')
assert.equal(smallEnought([5, 4, 3, 2, 1], 4), false)
assert.equal(smallEnought([2, 4, 3, 2, 1], 4), true)
assert.equal(smallEnought([4, 4, 3, 2, 1], 4), true)
assert.equal(smallEnought([2, 4, 3, 2, 5], 4), false)
assert.equal(smallEnought([2, 7, 3, 2, 5], 4), false)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Extended version