Skip to content

Commit da646f7

Browse files
committed
Indentation Correction
1 parent 9878882 commit da646f7

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

algorithms/string/karp_rabin.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,33 @@ var base = 997;
4444
var karpRabin = function (a, b) {
4545
var aLength = a.length;
4646
var bLength = b.length;
47-
var hashValue = hashFunction(b);
47+
var rs = hashFunction(b);
4848
var newString = [];
4949

5050
for (var i = 0; i < bLength; i++) {
5151
newString.push(a.charAt(i));
5252
}
5353

54-
var newStringHashValue = hashFunction(newString.join(''));
54+
var rt = hashFunction(newString.join(''));
5555

56-
if (hashValue === newStringHashValue && checkEquality(b, newString.join(''))) {
56+
if (rs === rt && checkEquality(b, newString.join(''))) {
5757
return true;
5858
}
5959
else {
6060
for (i = 1; i < aLength; i++) {
6161
var previousCharacter = newString[0];
6262
var nextCharacter = a.charAt(i);
6363

64-
newStringHashValue = reHash(b.length, newStringHashValue, previousCharacter, nextCharacter);
64+
rt = reHash(
65+
bLength,
66+
rt,
67+
previousCharacter,
68+
nextCharacter
69+
);
6570
newString.shift();
6671
newString.push(nextCharacter);
6772

68-
if (hashValue === newStringHashValue && checkEquality(b, newString.join(''))) {
73+
if (rs === rt && checkEquality(b, newString.join(''))) {
6974
return true;
7075
}
7176
}

test/algorithms/string/karp_rabin.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121
*/
2222
'use strict';
2323

24-
var karp_rabin = require('../../../algorithms/string/karp_rabin'),
24+
var karpRabin = require('../../../algorithms/string/karp_rabin'),
2525
assert = require('assert');
2626

2727
describe('Karp-Rabin', function () {
2828
it('should verify if a string is contained in another string',
2929
function () {
30-
assert.equal(karp_rabin('', ''), true);
31-
assert.equal(karp_rabin('a', 'b'), false);
32-
assert.equal(karp_rabin('b', 'a'), false);
30+
assert.equal(karpRabin('', ''), true);
31+
assert.equal(karpRabin('a', 'b'), false);
32+
assert.equal(karpRabin('b', 'a'), false);
3333

3434
// ' tes' is contained in 'super test'
35-
assert.equal(karp_rabin('super test', ' tes'), true);
35+
assert.equal(karpRabin('super test', ' tes'), true);
3636
});
3737
});

0 commit comments

Comments
 (0)