-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecodeQQId.js
35 lines (31 loc) · 952 Bytes
/
decodeQQId.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
//A QQid is a string of numbers
//This challenge is to decode a QQid
//You are given a encoded QQid
//You will get the correct QQId by following the steps below
//1. Delete the first number, move the 2nd number to the end of the QQid
//2. Delete the 3rd number, move the 4th number to the end of the QQid
//3. Delete the 5th number, move the 6th number to the end of the QQid
//...
//keep doing so until there is no number left
//concat all the deleted numbers in deletion order
//the concated string is the decoded id
function decodeQQId (encodedQQId) {
if (typeof (encodedQQId) !== 'string') {
return ''
}
let decodedQQId = '';
let start = 0;
let end = encodedQQId.length;
while (start < end) {
if (start % 2 === 0) {
decodedQQId += encodedQQId.charAt(start)
start++
} else {
encodedQQId += encodedQQId.charAt(start)
start++
end++
}
}
return decodedQQId
}
module.exports = decodeQQId