-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparens.js
More file actions
executable file
·41 lines (32 loc) · 775 Bytes
/
parens.js
File metadata and controls
executable file
·41 lines (32 loc) · 775 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
Parens checker.
Accepts one string, multilined, as input, returning T for mismatched parens or F
January 23, 2018
*/
let unbalanced = (instring)=>{
let counter = 0;
for (let c of instring){
console.log(`Looking now at ${c}.`);
if (c ==='('){ counter += 1;}
if (c ===')'){ counter -= 1;}
console.log(`afterwards counter is ${counter}.`);
}
return (counter===0) ? false : true;
}
let x = ` (((((`;
if (unbalanced(x)){
console.log(`The parens are not balanced.`);
} else {
console.log('The parens are balanced');
}
let flippit =(word)=> {
let letters = [];
// set for final pos'n
let position = word.length -1;
for (c in word){
letters[position] = word[c];
position -=1;
}
return letters.join("");
}
console.log(flippit("horsefeathers"));