Please help javascript masters. I have an array:
["G", "A", ".", ".", ".", ".", ".", ".", "E²", "…", ".", "~", "C²", "D²", "~", "C²", "."]
and the output should be
["G", "A......", "E²….~, "C²", "D²~", "C²."]
All Dot(.), hellip(…) and tilde(~) should stick with the previous index of an array.
My current code for now is this. I don't know what to do next because I'm not familiar all the built in functions in javascript.
var newArr = ["G", "A", ".", ".", ".", ".", ".", ".", "E²", "…", ".", "~", "C²", "D²", "~", "C²", "."];
for(var i=0; i<newArr.length; i++)
{
if(/[\ \…\~\.\…\*\_\/]/g.test(newArr[i]))
{
// delete this index and transfer current value to previous index
}
}
console.log(newArr);
This should work:
var str = ["G", "A", ".", ".", ".", ".", ".", ".", "E²", "…", ".", "~", "C²", "D²", "~", "C²", "."];
var newStr = str.join('').match(/([\w][^\w]*)/ig);
console.log(newStr);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With