-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Hashmap functionality added #42
Closed
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a19d97b
New Hashmap functionality added
DADDY-DOUBLESHOT 551b86d
description added
DADDY-DOUBLESHOT dd2e676
Update data.json (#61)
dikshantgautam2k c1c98a1
Format dd2e676
1436317
changes
DADDY-DOUBLESHOT 7c2f25c
Merge branch 'Opentek-Org:main' into main-new
DADDY-DOUBLESHOT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,36 +1,59 @@ | ||
let array = require("./data/data.json"); | ||
let inspireArray = require("./data/inspire.json"); | ||
let viewed = new Array(array.length); //hashtable | ||
|
||
|
||
function initialize() { | ||
//call this function before using the getNewRandomLine() | ||
viewed.fill(0, 0); | ||
} | ||
let favline = {}; | ||
|
||
function randomInt(min, max) { | ||
return Math.floor(Math.random() * (max - min) + min); | ||
return Math.floor(Math.random() * (max - min) + min); | ||
} | ||
|
||
module.exports.getRandomLine = function (type) { | ||
let index = randomInt(0, array.length); | ||
switch (type) { | ||
case "isp": | ||
index = randomInt(0, inspireArray.length); | ||
return inspireArray[index].line; | ||
default: | ||
return array[index].line; | ||
} | ||
module.exports.getRandomLine = function(type) { | ||
let index = randomInt(0, array.length); | ||
viewed[index] = 1; | ||
switch (type) { | ||
case "isp": | ||
index = randomInt(0, inspireArray.length); | ||
return inspireArray[index].line; | ||
default: | ||
return array[index].line; | ||
} | ||
}; | ||
module.exports.getNewRandomLine = function() { | ||
//new function to know which line was prevoiulsy generated and to not generate it again this time | ||
|
||
module.exports.getLines = function (type) { | ||
let index = randomInt(0, array.length); | ||
switch (type) { | ||
case "isp": | ||
index = randomInt(0, inspireArray.length); | ||
favline.line = inspireArray[index].line; | ||
favline.book = inspireArray[index].book; | ||
favline.author = inspireArray[index].author; | ||
return favline; | ||
default: | ||
favline.line = array[index].line; | ||
favline.book = array[index].book; | ||
favline.author = array[index].author; | ||
return favline; | ||
} | ||
let index = randomInt(0, array.length); | ||
let cnt = Number(array.length); | ||
while (!viewed[index] && cnt >= 0) { | ||
//O(1) search | ||
index = randomInt(0, array.length); | ||
cnt--; | ||
} | ||
if (cnt < 0) { | ||
index = randomInt(0, array.length); | ||
} | ||
viewed[index] = 1; | ||
return array[index].line; | ||
}; | ||
|
||
module.exports.getLines = function(type) { | ||
let index = randomInt(0, array.length); | ||
switch (type) { | ||
case "isp": | ||
index = randomInt(0, inspireArray.length); | ||
favline.line = inspireArray[index].line; | ||
favline.book = inspireArray[index].book; | ||
favline.author = inspireArray[index].author; | ||
return favline; | ||
default: | ||
favline.line = array[index].line; | ||
favline.book = array[index].book; | ||
favline.author = array[index].author; | ||
return favline; | ||
} | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, here it will check if the line is previously generated or not, and if it is not generated then it will return the line?
It will be great if you can provide a short description of what your code exactly does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah ohk i will just desribe those