Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.57 KB | None | 0 0
  1. let neededData = {
  2. ajza: [
  3. 1,
  4. 149,
  5. 260,
  6. 386,
  7. 517,
  8. 641,
  9. 751,
  10. 900,
  11. 1042,
  12. 1201,
  13. 1328,
  14. 1479,
  15. 1649,
  16. 1803,
  17. 2030,
  18. 2215,
  19. 2484,
  20. 2674,
  21. 2876,
  22. 3215,
  23. 3386,
  24. 3564,
  25. 3733,
  26. 4090,
  27. 4265,
  28. 4511,
  29. 4706,
  30. 5105,
  31. 5242,
  32. 5673,
  33. 6236,
  34. ],
  35. juzMapping: [
  36. {
  37. id: 1,
  38. juz_number: 1,
  39. verse_mapping: {
  40. '1': '1-7',
  41. '2': '1-141',
  42. },
  43. },
  44. {
  45. id: 2,
  46. juz_number: 2,
  47. verse_mapping: {
  48. '2': '142-252',
  49. },
  50. },
  51. {
  52. id: 3,
  53. juz_number: 3,
  54. verse_mapping: {
  55. '2': '253-286',
  56. '3': '1-92',
  57. },
  58. },
  59. {
  60. id: 4,
  61. juz_number: 4,
  62. verse_mapping: {
  63. '3': '93-200',
  64. '4': '1-23',
  65. },
  66. },
  67. {
  68. id: 5,
  69. juz_number: 5,
  70. verse_mapping: {
  71. '4': '24-147',
  72. },
  73. },
  74. {
  75. id: 6,
  76. juz_number: 6,
  77. verse_mapping: {
  78. '4': '148-176',
  79. '5': '1-81',
  80. },
  81. },
  82. {
  83. id: 7,
  84. juz_number: 7,
  85. verse_mapping: {
  86. '5': '82-120',
  87. '6': '1-110',
  88. },
  89. },
  90. {
  91. id: 8,
  92. juz_number: 8,
  93. verse_mapping: {
  94. '6': '111-165',
  95. '7': '1-87',
  96. },
  97. },
  98. {
  99. id: 9,
  100. juz_number: 9,
  101. verse_mapping: {
  102. '7': '88-206',
  103. '8': '1-40',
  104. },
  105. },
  106. {
  107. id: 10,
  108. juz_number: 10,
  109. verse_mapping: {
  110. '8': '41-75',
  111. '9': '1-92',
  112. },
  113. },
  114. {
  115. id: 11,
  116. juz_number: 11,
  117. verse_mapping: {
  118. '9': '93-129',
  119. '10': '1-109',
  120. '11': '1-5',
  121. },
  122. },
  123. {
  124. id: 12,
  125. juz_number: 12,
  126. verse_mapping: {
  127. '11': '6-123',
  128. '12': '1-52',
  129. },
  130. },
  131. {
  132. id: 13,
  133. juz_number: 13,
  134. verse_mapping: {
  135. '12': '53-111',
  136. '13': '1-43',
  137. '14': '1-52',
  138. },
  139. },
  140. {
  141. id: 14,
  142. juz_number: 14,
  143. verse_mapping: {
  144. '15': '1-99',
  145. '16': '1-128',
  146. },
  147. },
  148. {
  149. id: 15,
  150. juz_number: 15,
  151. verse_mapping: {
  152. '17': '1-111',
  153. '18': '1-74',
  154. },
  155. },
  156. {
  157. id: 16,
  158. juz_number: 16,
  159. verse_mapping: {
  160. '18': '75-110',
  161. '19': '1-98',
  162. '20': '1-135',
  163. },
  164. },
  165. {
  166. id: 17,
  167. juz_number: 17,
  168. verse_mapping: {
  169. '21': '1-112',
  170. '22': '1-78',
  171. },
  172. },
  173. {
  174. id: 18,
  175. juz_number: 18,
  176. verse_mapping: {
  177. '23': '1-118',
  178. '24': '1-64',
  179. '25': '1-20',
  180. },
  181. },
  182. {
  183. id: 19,
  184. juz_number: 19,
  185. verse_mapping: {
  186. '25': '21-77',
  187. '26': '1-227',
  188. '27': '1-55',
  189. },
  190. },
  191. {
  192. id: 20,
  193. juz_number: 20,
  194. verse_mapping: {
  195. '27': '56-93',
  196. '28': '1-88',
  197. '29': '1-45',
  198. },
  199. },
  200. {
  201. id: 21,
  202. juz_number: 21,
  203. verse_mapping: {
  204. '29': '46-69',
  205. '30': '1-60',
  206. '31': '1-34',
  207. '32': '1-30',
  208. '33': '1-30',
  209. },
  210. },
  211. {
  212. id: 22,
  213. juz_number: 22,
  214. verse_mapping: {
  215. '33': '31-73',
  216. '34': '1-54',
  217. '35': '1-45',
  218. '36': '1-27',
  219. },
  220. },
  221. {
  222. id: 24,
  223. juz_number: 24,
  224. verse_mapping: {
  225. '39': '32-75',
  226. '40': '1-85',
  227. '41': '1-46',
  228. },
  229. },
  230. {
  231. id: 23,
  232. juz_number: 23,
  233. verse_mapping: {
  234. '36': '28-83',
  235. '37': '1-182',
  236. '38': '1-88',
  237. '39': '1-31',
  238. },
  239. },
  240. {
  241. id: 25,
  242. juz_number: 25,
  243. verse_mapping: {
  244. '41': '47-54',
  245. '42': '1-53',
  246. '43': '1-89',
  247. '44': '1-59',
  248. '45': '1-37',
  249. },
  250. },
  251. {
  252. id: 26,
  253. juz_number: 26,
  254. verse_mapping: {
  255. '46': '1-35',
  256. '47': '1-38',
  257. '48': '1-29',
  258. '49': '1-18',
  259. '50': '1-45',
  260. '51': '1-30',
  261. },
  262. },
  263. {
  264. id: 27,
  265. juz_number: 27,
  266. verse_mapping: {
  267. '51': '31-60',
  268. '52': '1-49',
  269. '53': '1-62',
  270. '54': '1-55',
  271. '55': '1-78',
  272. '56': '1-96',
  273. '57': '1-29',
  274. },
  275. },
  276. {
  277. id: 28,
  278. juz_number: 28,
  279. verse_mapping: {
  280. '58': '1-22',
  281. '59': '1-24',
  282. '60': '1-13',
  283. '61': '1-14',
  284. '62': '1-11',
  285. '63': '1-11',
  286. '64': '1-18',
  287. '65': '1-12',
  288. '66': '1-12',
  289. },
  290. },
  291. {
  292. id: 29,
  293. juz_number: 29,
  294. verse_mapping: {
  295. '67': '1-30',
  296. '68': '1-52',
  297. '69': '1-52',
  298. '70': '1-44',
  299. '71': '1-28',
  300. '72': '1-28',
  301. '73': '1-20',
  302. '74': '1-56',
  303. '75': '1-40',
  304. '76': '1-31',
  305. '77': '1-50',
  306. },
  307. },
  308. {
  309. id: 30,
  310. juz_number: 30,
  311. verse_mapping: {
  312. '78': '1-40',
  313. '79': '1-46',
  314. '80': '1-42',
  315. '81': '1-29',
  316. '82': '1-19',
  317. '83': '1-36',
  318. '84': '1-25',
  319. '85': '1-22',
  320. '86': '1-17',
  321. '87': '1-19',
  322. '88': '1-26',
  323. '89': '1-30',
  324. '90': '1-20',
  325. '91': '1-15',
  326. '92': '1-21',
  327. '93': '1-11',
  328. '94': '1-8',
  329. '95': '1-8',
  330. '96': '1-19',
  331. '97': '1-5',
  332. '98': '1-8',
  333. '99': '1-8',
  334. '100': '1-11',
  335. '101': '1-11',
  336. '102': '1-8',
  337. '103': '1-3',
  338. '104': '1-9',
  339. '105': '1-5',
  340. '106': '1-4',
  341. '107': '1-7',
  342. '108': '1-3',
  343. '109': '1-6',
  344. '110': '1-3',
  345. '111': '1-5',
  346. '112': '1-4',
  347. '113': '1-5',
  348. '114': '1-6',
  349. },
  350. },
  351. ],
  352. juzByVerseTotalNumber: [
  353. { juz: 1, chapter_in_juz: ['1', '2'] },
  354. { juz: 2, chapter_in_juz: ['2'] },
  355. { juz: 3, chapter_in_juz: ['2', '3'] },
  356. { juz: 4, chapter_in_juz: ['3', '4'] },
  357. { juz: 5, chapter_in_juz: ['4'] },
  358. { juz: 6, chapter_in_juz: ['4', '5'] },
  359. { juz: 7, chapter_in_juz: ['5', '6'] },
  360. { juz: 8, chapter_in_juz: ['6', '7'] },
  361. { juz: 9, chapter_in_juz: ['7', '8'] },
  362. { juz: 10, chapter_in_juz: ['8', '9'] },
  363. { juz: 11, chapter_in_juz: ['9', '10', '11'] },
  364. { juz: 12, chapter_in_juz: ['11', '12'] },
  365. { juz: 13, chapter_in_juz: ['12', '13', '14'] },
  366. { juz: 14, chapter_in_juz: ['15', '16'] },
  367. { juz: 15, chapter_in_juz: ['17', '18'] },
  368. { juz: 16, chapter_in_juz: ['18', '19', '20'] },
  369. { juz: 17, chapter_in_juz: ['21', '22'] },
  370. { juz: 18, chapter_in_juz: ['23', '24', '25'] },
  371. { juz: 19, chapter_in_juz: ['25', '26', '27'] },
  372. { juz: 20, chapter_in_juz: ['27', '28', '29'] },
  373. { juz: 21, chapter_in_juz: ['29', '30', '31', '32', '33'] },
  374. { juz: 22, chapter_in_juz: ['33', '34', '35', '36'] },
  375. { juz: 23, chapter_in_juz: ['39', '40', '41'] },
  376. { juz: 24, chapter_in_juz: ['36', '37', '38', '39'] },
  377. { juz: 25, chapter_in_juz: ['41', '42', '43', '44', '45'] },
  378. { juz: 26, chapter_in_juz: ['46', '47', '48', '49', '50', '51'] },
  379. { juz: 27, chapter_in_juz: ['51', '52', '53', '54', '55', '56', '57'] },
  380. { juz: 28, chapter_in_juz: ['58', '59', '60', '61', '62', '63', '64', '65', '66'] },
  381. { juz: 29, chapter_in_juz: ['67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77'] },
  382. {
  383. juz: 30,
  384. chapter_in_juz: [
  385. '78',
  386. '79',
  387. '80',
  388. '81',
  389. '82',
  390. '83',
  391. '84',
  392. '85',
  393. '86',
  394. '87',
  395. '88',
  396. '89',
  397. '90',
  398. '91',
  399. '92',
  400. '93',
  401. '94',
  402. '95',
  403. '96',
  404. '97',
  405. '98',
  406. '99',
  407. '100',
  408. '101',
  409. '102',
  410. '103',
  411. '104',
  412. '105',
  413. '106',
  414. '107',
  415. '108',
  416. '109',
  417. '110',
  418. '111',
  419. '112',
  420. '113',
  421. '114',
  422. ],
  423. },
  424. ],
  425. }
  426.  
  427. juzMemory() {
  428. // @saveroo Dirty Approach
  429. // Regarding handling Mapped process, from memorization[{chapter[]}] to juz[memorization[chapter{verses[]}]
  430. // Problem:
  431. // -memorization[chapter{}] and juz data are separated,
  432. // Expectation:
  433. // -Wanted to display and order by the juz, but not all the memorized verse,
  434. // -if condition of memorized verses is unmet the criteria of juz, it wont be displayed.
  435. // as example we have memorization at Chapter 1:1-7, chapter 2:1-2, chapter 55:10
  436. // [Juz 1] << DISPLAYED
  437. // [Memorization]
  438. // [Chapter 1] 1:1-7
  439. // [Chapter 2] 1:1-141
  440. // [Juz 2] << NOT DISPLAYED
  441. // [Memorization]
  442. // [Chapter]
  443. // [Juz 27] << DISPLAYED
  444. // [Memorization]
  445. // [Chapter 55] 10 (Our Memorized verses equal inRange between the constraint to be considered as juz 27)
  446. // @2019
  447.  
  448. // You dont need Lodash
  449. const inRange = (num, a, b = 0) => Math.min(a, b) <= num && num < Math.max(a, b);
  450.  
  451. // To reduce typing overhead, i put it thereeee, immutable const
  452. const jz = this.juzByVerseTotalNumber;
  453. const jm = this.juzMapping;
  454. const mem = this.memorizations;
  455. const memmap = mem.map(i => i.chapter);
  456.  
  457. // TODO: should have better approach
  458. // This is the main array to contains the transformed 30juz.
  459. let arr = [];
  460.  
  461. // So i dont forget how to iterate thru it...
  462. // 1. first iterate the juz Array from 1 to 30
  463. for (let i = 0; i < jz.length; i++) {
  464. // Initialize empty array to hold morphed Juz array from 1 to 30
  465. // This array after iteration will reset. to contain new item in 2nd iteration.
  466. let arrChap = [];
  467.  
  468. // The object to be pushed thru
  469. let objUpper = {
  470. juz: jz[i].juz,
  471. juz_start_at_verse: this.ajza[i + 1],
  472. };
  473.  
  474. // 2. Iterate thru the chapter, in 30 iteration there is 7 iteration, to push, if chapter is included in the current juz
  475. for (let j = 0; j < memmap.length; j++) {
  476. if (jm[i].verse_mapping[`${memmap[j].chapter_number}`]) {
  477. let jmap = jm[i].verse_mapping[`${memmap[j].chapter_number}`];
  478. let splt = jmap.split('-');
  479. if (inRange(mem[j].verses.length, splt[0], splt[1] + 1)) arrChap.push(mem[j]);
  480. }
  481.  
  482. // ## Uncomment if chapter want to be included in juz, regardless condition of memorized verse is unmet
  483. // If the current mapped chapter in memorization included in 30 JUZ iteration,
  484. // then push to array which reseted in every new iteration
  485. // if (jz[i].chapter_in_juz.includes(`${memmap[j].chapter_number}`)) {
  486. //
  487. // // push memorization which contain a chapter, since chapter has one-to-one relationship.
  488. // // arrChap.push(mem[j]);
  489. // }
  490. }
  491.  
  492. // After done the 2nd iteration, then added props to Object which contain juz number and chapter array,
  493. // Then push to main array
  494. objUpper.chapter = arrChap;
  495. arr.push(objUpper);
  496. }
  497.  
  498. // Returned filter to remove empty array
  499. return arr.filter(i => i.chapter.length !== 0);
  500. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement