-
Notifications
You must be signed in to change notification settings - Fork 2
/
10-truncate_a_string.js
executable file
·36 lines (31 loc) · 1.13 KB
/
10-truncate_a_string.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a '...' ending. Note that the three dots at the end add to the string length.*/
function truncate(str, num) {
if (str.length <= num) {
return str
} else {
return str.substring(0, num) + "..."
}
}
console.log(truncate("A-tisket a-tasket A green and yellow basket", 11))
//Passing Tests
var chai = require("chai")
var expect = chai.expect
var assert = require("assert")
/* expect(truncate("A-tisket a-tasket A green and yellow basket", 11)).to.eqls(
"A-tisket...",
) */
/* assert(
truncate(
"A-tisket a-tasket A green and yellow basket",
"A-tisket a-tasket A green and yellow basket".length,
) === "A-tisket a-tasket A green and yellow basket",
"should not truncate if firsst argument string is = length",
) */
/* assert.strictEqual(
truncate(
"A-tisket a-tasket A green and yellow basket",
"A-tisket a-tasket A green and yellow basket".length + 1,
),
"A-tisket a-tasket A green and yellow basket",
"should not truncate if first argument string is < length",
) */