Commit 7bd4ff00 authored by Mikaël Salson's avatar Mikaël Salson
Browse files

tools.js: endsWith() function

endsWith method in the String class is from a recent ECMAScript standard
and is therefore not well supported.

Instead we provide a endsWith function that will make the same job.
parent 88c6e924
......@@ -43,6 +43,12 @@ function tsvToArray(allText) {
return lines;
}
function endsWith(sequence, end) {
if (sequence.length < end.length)
return false;
return sequence.substr(sequence.length - end.length, end.length) == end
}
/**
* With insertions, IMGT positions must be understood with the insertions
* removed. As we display the original sequence and not the corrected one, we
......@@ -72,7 +78,7 @@ function correctIMGTPositionsForInsertions(data) {
// Shift all positions that are after insertions
for (var item in data) {
if (item.endsWith(' end') || item.endsWith(' start')) {
if (endsWith(item, ' end') || endsWith(item, ' start')) {
var seq_position = parseInt(data[item])
var after_insertions = 0;
var i = 0
......
......@@ -58,6 +58,14 @@ asyncTest("processImgtContents", function () {
}
);
test("endsWith", function() {
equal(endsWith("toto", "o"), true, "toto finishes with o")
equal(endsWith("tota", "o"), false, "tota doesn't finish with o")
equal(endsWith("o", "toto"), false, "o doesn't finish with toto")
equal(endsWith("toto", ""), true, "toto finishes with empty string")
equal(endsWith("tota", "to"), false, "tota doesn't finish with to")
})
test("correctIMGTPositionsForInsertions", function() {
data = {
'V-REGION identity % (with ins/del events)': "98.2%",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment