SIGN IN SIGN UP

Algorithms and Data Structures implemented in JavaScript for beginners, following best practices.

34084 0 0 JavaScript
import {
ternarySearchRecursive,
ternarySearchIterative
} from '../TernarySearch'
2021-07-24 22:48:18 +08:00
test('should return the index of a number in an array of numbers:', () => {
const indexNumber = ternarySearchRecursive([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3)
expect(indexNumber).toBe(2)
})
test('should return the index of a number in an array of numbers:', () => {
const indexNumber = ternarySearchIterative([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 8)
expect(indexNumber).toBe(7)
})
test('should return the index of a number in an array of numbers:', () => {
const indexNumber = ternarySearchRecursive([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0)
expect(indexNumber).toBe(-1)
})
test('should return the index of a number in an array of numbers:', () => {
const indexNumber = ternarySearchIterative(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
12
)
2021-07-24 22:48:18 +08:00
expect(indexNumber).toBe(-1)
})
test('should return the index of a string in an array of strings:', () => {
const indexNumber = ternarySearchRecursive(
['Ali', 'Cathrynli', 'Josuke', 'Thomas'],
'Cathrynli'
)
2021-07-24 22:48:18 +08:00
expect(indexNumber).toBe(1)
})
test('should return the index of a string in an array of strings:', () => {
const indexNumber = ternarySearchRecursive(
['Ali', 'Cathrynli', 'Josuke', 'Thomas'],
'Josuke'
)
2021-07-24 22:48:18 +08:00
expect(indexNumber).toBe(2)
})
test('should return the index of a string in an array of strings:', () => {
const indexNumber = ternarySearchRecursive(
['Ali', 'Cathrynli', 'Josuke', 'Thomas'],
'Angela'
)
2021-07-24 22:48:18 +08:00
expect(indexNumber).toBe(-1)
})