'How to console log pairs in array
For example I have this string "()[]|}" and I want to compare each characters with eachother, but first I can't get the loop to work correctly. For the first log it works correctly, but after instead of going +1 it should go +2 I believe so it doesn't start from ). How do can I do this properly?
function isValid(s) {
let temp = s.split("");
for (let i = 0; i < s.length/2; i++) {
console.log(temp[i], temp[i+1]);
}
};
isValid("()[]|}");
I want to log this
( )
[ ]
| }
not
( )
) [
[ ]
Solution 1:[1]
If the question is 'how do I increment by two instead of by 1', use i += 2 instead of i++ (since the increment operator only increments by 1)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jren510 |
