Skip to content

Commit 50e48a1

Browse files
committed
Merge branch 'HEAD' of git@github.com:kvz/phpjs.git
2 parents 4297f48 + a14c2d7 commit 50e48a1

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

_workbench/strings/similar_text.js renamed to functions/strings/similar_text.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
function similar_text (first, second) {
2-
/*
3-
* This is a direct port from PHP source code with a few modifications. May be buggy.
4-
* This function still needs to be checked and unit tested.
5-
* Other goals are to switch from recursive to iterative approach
6-
*
7-
* Original by: Rafał Kukawski
8-
*/
2+
// http://kevin.vanzonneveld.net
3+
// + original by: Rafał Kukawski (http://blog.kukawski.pl)
4+
// * example 1: similar_text('Hello World!', 'Hello phpjs!');
5+
// * returns 1: 7
6+
// * example 2: similar_text('Hello World!', null);
7+
// * returns 2: 0
8+
9+
if (first === null || second === null || typeof first === "undefined" || typeof second === "undefined") {
10+
return 0;
11+
}
12+
13+
first += ''; second += '';
14+
915
var pos1 = 0, pos2 = 0, max = 0,
1016
firstLength = first.length, secondLength = second.length,
1117
p, q, l, sum;

functions/strings/sprintf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function sprintf ( ) {
124124
case 'u': return formatBaseX(value, 10, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
125125
case 'i':
126126
case 'd':
127-
number = parseInt(+value, 10);
127+
number = (+value) | 0;
128128
prefix = number < 0 ? '-' : positivePrefix;
129129
value = prefix + pad(String(Math.abs(number)), precision, '0', false);
130130
return justify(value, prefix, leftJustify, minWidth, zeroPad);

0 commit comments

Comments
 (0)