Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
6
test/sortedIndex/sortedIndex.js
Normal file
6
test/sortedIndex/sortedIndex.js
Normal file
@ -0,0 +1,6 @@
|
||||
const sortedIndex = (arr, n) => {
|
||||
const isDescending = arr[0] > arr[arr.length - 1];
|
||||
const index = arr.findIndex(el => (isDescending ? n >= el : n <= el));
|
||||
return index === -1 ? arr.length : index;
|
||||
};
|
||||
module.exports = sortedIndex;
|
||||
10
test/sortedIndex/sortedIndex.test.js
Normal file
10
test/sortedIndex/sortedIndex.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const sortedIndex = require('./sortedIndex.js');
|
||||
|
||||
|
||||
test('sortedIndex is a Function', () => {
|
||||
expect(sortedIndex).toBeInstanceOf(Function);
|
||||
});
|
||||
t.equal(sortedIndex([5, 3, 2, 1], 4), 1, "Returns the lowest index at which value should be inserted into array in order to maintain its sort order.");
|
||||
t.equal(sortedIndex([30, 50], 40), 1, "Returns the lowest index at which value should be inserted into array in order to maintain its sort order.");
|
||||
|
||||
Reference in New Issue
Block a user