forked from jfarmer/exercises-js-fundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectShorterThan.js
32 lines (29 loc) · 1.21 KB
/
selectShorterThan.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* Given an array of strings and a threshold length, returns a new array
* consisting of only the strings with length strictly less than the
* given threshold.
*
* Return an empty array if no such strings exist.
*
* @example
* selectShorterThan(['', 'aaa', 'bb', 'c', 'dddd'], 0); // => []
* selectShorterThan(['', 'aaa', 'bb', 'c', 'dddd'], 1); // => ['']
* selectShorterThan(['', 'aaa', 'bb', 'c', 'dddd'], 2); // => ['', 'c']
* selectShorterThan(['', 'aaa', 'bb', 'c', 'dddd'], 3); // => ['', 'bb', 'c']
* selectShorterThan(['', 'aaa', 'bb', 'c', 'dddd'], 4); // => ['', 'aaa', 'bb', 'c']
* selectShorterThan(['', 'aaa', 'bb', 'c', 'dddd'], 5); // => ['', 'aaa', 'bb', 'c', 'dddd']
*
* @param {string[]} array - An array of strings
* @param {number} threshold - A length threshold
* @returns {string[]} An array of all strings in the input array with length
* strictly less the given threshold
*/
function selectShorterThan(array, threshold) {
// This is your job. :)
}
if (require.main === module) {
console.log('Running sanity checks for selectShorterThan:');
// Add your own sanity checks here.
// How else will you be sure your code does what you think it does?
}
module.exports = selectShorterThan;