Created
May 29, 2017 05:26
-
-
Save vaidehijoshi/0332c9ae64b4adb387caeeebcced4ce3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function bookHashing(bookTitle, hashTableSize) { | |
// Remove any spaces from book title. | |
var strippedBookTitle = bookTitle.replace(/\s/g, '') | |
// Divide the length of the title by the hash table size. | |
// Return the remainder. | |
return strippedBookTitle.length % hashTableSize; | |
} | |
bookHashing("The Grapes of Wrath", 12); | |
// 4 | |
bookHashing("The Sound and the Fury", 12); | |
// 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment