quran-meta
Version:
Library with meta data and functionality related to Holy Quran
20 lines (18 loc) • 596 B
JavaScript
import { checkValidAyahId } from "./validation.js";
import { JuzList } from "./lists/juzList.js";
import { binarySearch } from "./utils.js";
//#region src/findJuzByAyahId.ts
/**
* Finds the Juz (part) of the Quran that contains the given Ayah (verse) ID.
*
* @param ayahId - The ID of the Ayah (verse) to find the Juz for.
* @returns The Juz (part) of the Quran that contains the given Ayah ID.
*/
function findJuzByAyahId(ayahId) {
checkValidAyahId(ayahId);
const jj = binarySearch(JuzList, ayahId);
const juz = jj < 0 ? -jj - 2 : jj;
return juz;
}
//#endregion
export { findJuzByAyahId };