I've written a function to turn a string such as 'aaazeeeee' into a new string of 'aaa z eeeee'
this is the code I've tried that works
const groupCharacters = signature => {
let newSignature = "", arr = [];
let result = [...signature].reduce((accumulator, element, index) => {
// check if last element in accumulator matches current element
if (accumulator[accumulator.length -1] !== element) {
// push accumulator into array
arr.push(accumulator);
// set newSignature as new element
newSignature = element;
} else {
// else add element to newSignature
newSignature = accumulator += element;
}
// if is last item, push to array
if (index === signature.length - 1) arr.push(element);
return newSignature;
})
return arr;
}
console.log(groupCharacters('aabaaaaa'));
Is it possibile to use an inline return with javascript map function? Instead of doing array.map(token => { var x=new Object(); x[token]=words[token]; return x;} ) I would like to do it inline as ...
Is it possibile to use an inline return with javascript map function? Instead of doing array.map(token => { var x=new Object(); x[token]=words[token]; return x;} ) I would like to do it inline as ...
I have the following code: const array = [{ a: 'a', b: 'b' }]; console.log(...array); const store = { obj: ...array } console.log will print the results just fine. However, ...
I have the following code: const array = [{ a: 'a', b: 'b' }]; console.log(...array); const store = { obj: ...array } console.log will print the results just fine. However, ...
I have a simple react component that uses react hooks. I'm using useEffect and useState. The problem is that i realized my API is getting huge amount of hits, after debugging i see that useEffect is ...
I have a simple react component that uses react hooks. I'm using useEffect and useState. The problem is that i realized my API is getting huge amount of hits, after debugging i see that useEffect is ...
I just noticed an odd cookie policy problem that only affects IE. I could only test on IE11. Perhaps you know a workaround? Step 1. This requires 2 domains. We'll call them cart.com and tracking.com. ...
I just noticed an odd cookie policy problem that only affects IE. I could only test on IE11. Perhaps you know a workaround? Step 1. This requires 2 domains. We'll call them cart.com and tracking.com. ...