-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathin.js
More file actions
25 lines (22 loc) · 663 Bytes
/
in.js
File metadata and controls
25 lines (22 loc) · 663 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 generateWord(input) {
let word = [];
let backlog = [];
input.map((alphabet, i) => {
if (word.length < 1) {
return word.push(alphabet.charAt(0), alphabet.charAt(2));
} else {
if (word.indexOf(alphabet[2]) >= 0) {
return word.splice(word.indexOf(alphabet[2]), 0, alphabet[0]);
} else if (word.indexOf(alphabet[0]) >= 0) {
return word.splice(word.indexOf(alphabet[0]) + 1, 0, alphabet[2]);
} else {
backlog = alphabet;
}
}
});
if (backlog) {
word.splice(word.indexOf(backlog[2]), 0, backlog[0]);
}
return word.join("");
}
console.log(generateWord(["M>P","L>A","A>M"]));