forked from nan-academy/js-training
-
Notifications
You must be signed in to change notification settings - Fork 1
/
repeat.js
22 lines (19 loc) · 785 Bytes
/
repeat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict'
/*
* Create a `repeat` function that takes a string and a number as parameters
* and return the repeated string by the given number
* Like the method https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
* Of course you may not use the method directly
*
*/
//* Begin of tests
const assert = require('assert')
assert.strictEqual(typeof repeat, 'function')
assert.strictEqual(repeat.length, 2)
assert.strictEqual(repeat.toString().includes('.repeat'), false)
assert.strictEqual(repeat('a', 3), 'aaa')
assert.strictEqual(repeat('ba', 10), 'babababababababababa')
assert.strictEqual(repeat('pouet', 2), 'pouetpouet')
assert.strictEqual(repeat('haha', 1), 'haha')
assert.strictEqual(repeat('hehehe', 0), '')
// End of tests */