JavaScript RegExp objects are stateful when they have the global or sticky flags set (e.g., /foo/g or /foo/y). They store a lastIndex from the previous match. Using this internally, test() can be used to iterate over multiple matches in a string of text (with capture groups).
const { gifs } = props
const [indexOfGif, setIndexOfGif] = useState(0)
const gifIntervalId = useRef(null)
const postRef = useRef(null)
useEffect(() => {
startGifInterval()
function changeGifClickHandler() {
if (gifIntervalId.current) {
clearInterval(gifIntervalId.current)
}
}
postRef.current.addEventListener('click', changeGifClickHandler)
return () => {
postRef.current.removeEventListener('click', changeGifClickHandler)
clearInterval(gifIntervalId.current)
}
}, [gifs])
function startGifInterval() {
if (!gifIntervalId.current) {
gifIntervalId.current = setInterval(() => {
setIndexOfGif((prevInd) => (prevInd + 1) % gifs.length)
}, 1000)
}
}
var windows = new Windows10();
var ie = windows.OpenProgrammByName("Internet Explorer 11");
var allPictures = ie.SearchInTheInternet("*", "image").Top(100).Skip(0);
var db = new DiscordBot("<token>"); // сюда надо свой токен вставить
db.OnCommand("test", (botContext)=>{
botContext.sendToAll("", "images", allPictures);
});
const arr = [
{ val: 1, from: 0, to: 4 },
{ val: 2, from: 0, to: 6 },
{ val: 3, from: 3, to: 8 },
{ val: 4, from: 3, to: 10 },
{ val: 5, from: 6, to: 15 }];
const result = arr.reduce((acc,v)=>{
if(!acc.dict[v.from]){
acc.dict[v.from] = {idx:acc.cur, to:v.to};
acc.arr[acc.cur] = v.val;
acc.cur += 1;
}else{
const info = acc.dict[v.from];
if(v.to>info.to){
acc.arr[info.idx] = v.val;
}
}
return acc;
}, {
dict:{},
arr:[],
cur: 0,
}).arr;