-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkata.js
More file actions
25 lines (20 loc) · 700 Bytes
/
kata.js
File metadata and controls
25 lines (20 loc) · 700 Bytes
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
function genPasswd(key, str, pwLen) {
let password = "";
for (let i = 0; i < Math.ceil(pwLen / 2); i++) {
const indexFromStart = (key + i) % str.length;
const indexFromEnd = str.length - indexFromStart - 1;
password += str[indexFromStart] + str[indexFromEnd];
}
if (password.length > pwLen) password = password.slice(0, pwLen);
return password;
}
/*
const str = '0123456789';
const [key, pwLen] = [5, 12];
const password = genPasswd(key, str, pwLen);
assert.strictEqual(password, '546372819009');
*/
const str = '0123456789#';
const [key, pwLen] = [0, 15];
const password = genPasswd(key, str, pwLen);
assert.strictEqual(password, '0#1928374655647');