-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add surrounding context for Tanakh references
- Loading branch information
1 parent
4ecc2af
commit 0e32b45
Showing
61 changed files
with
76,870 additions
and
5,745 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {surroundingContext} from "../arrays"; | ||
|
||
test("context: zero", () => { | ||
const zero = () => surroundingContext(["a"], "a", 0); | ||
expect(zero).toThrow(); | ||
}); | ||
|
||
test("context: negative", () => { | ||
const negative = () => surroundingContext(["a"], "a", -1); | ||
expect(negative).toThrow(); | ||
}); | ||
|
||
test("single", () => { | ||
expect(surroundingContext(["a"], "a", 1)).toEqual(["a"]); | ||
expect(surroundingContext(["a"], "a", 10)).toEqual(["a"]); | ||
}); | ||
|
||
|
||
test("first", () => { | ||
expect(surroundingContext([10, 11, 12], 10, 1)).toEqual([10, 11]); | ||
expect(surroundingContext([10, 11, 12], 10, 2)).toEqual([10, 11, 12]); | ||
expect(surroundingContext([10, 11, 12], 10, 3)).toEqual([10, 11, 12]); | ||
}); | ||
|
||
|
||
test("middle", () => { | ||
expect(surroundingContext([10, 11, 12], 11, 1)).toEqual([10, 11, 12]); | ||
expect(surroundingContext([10, 11, 12], 11, 2)).toEqual([10, 11, 12]); | ||
expect(surroundingContext([10, 11, 12], 11, 3)).toEqual([10, 11, 12]); | ||
}); | ||
|
||
test("last", () => { | ||
expect(surroundingContext([10, 11, 12], 12, 1)).toEqual([11, 12]); | ||
expect(surroundingContext([10, 11, 12], 12, 2)).toEqual([10, 11, 12]); | ||
expect(surroundingContext([10, 11, 12], 12, 3)).toEqual([10, 11, 12]); | ||
}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function surroundingContext<T>(array: T[], item: T, context: number): T[] { | ||
if (context <= 0) throw new Error(`Invalid context: ${context} must be positive`); | ||
const index = array.indexOf(item); | ||
const start = Math.max(index - context, 0); | ||
return array.slice(start, index + context + 1); | ||
} |
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
Oops, something went wrong.