repeat

Check for repeated characters in a string Javascript

扶醉桌前 提交于 2019-11-27 02:19:08
问题 I was wondering if there is a way to check for repeated characters in a string without using double loop. Can this be done with recursion? An example of the code using double loop (return true or false based on if there are repeated characters in a string): var charRepeats = function(str) { for(var i = 0; i <= str.length; i++) { for(var j = i+1; j <= str.length; j++) { if(str[j] == str[i]) { return false; } } } return true; } Many thanks in advance! 回答1: (A recursive solution can be found at

How can I repeat the headers of an iTextSharp PdfPTable on each page?

人盡茶涼 提交于 2019-11-27 01:54:19
问题 How can I get iTextSharp to repeat the headers of a PdfPTable on each page of the generated PDF? 回答1: You just need to set the PdfPTable.HeaderRows property to the number of rows in your PdfPTable 's header like this: table.HeaderRows = 1; 来源: https://stackoverflow.com/questions/2062983/how-can-i-repeat-the-headers-of-an-itextsharp-pdfptable-on-each-page

Repeat jQuery ajax call

这一生的挚爱 提交于 2019-11-27 01:18:14
问题 How to repeat jQuery ajax call every 10 seconds? $(document).ready(function() { $.ajax({ type: "GET", url: "newstitle.php", data: "user=success", success: function(msg) { $(msg).appendTo("#edix"); } }); I've tried to wrap the $.ajax with a function and to call the function with setInterval $(document).ready(function() { function ajaxd() { $.ajax({ type: "GET", url: "newstitle.php", data: "user=success", success: function(msg) { $(msg).appendTo("#edix"); } }); } setInterval("ajaxd()",10000); }

do-while loop in R

放肆的年华 提交于 2019-11-27 00:50:09
问题 I was wondering about how to write do-while-style loop? I found this post: you can use repeat{} and check conditions whereever using if() and exit the loop with the "break" control word. I am not sure what it exactly means. Can someone please elaborate if you understand it and/or if you have a different solution? 回答1: Pretty self explanatory. repeat{ statements... if(condition){ break } } Or something like that I would think. To get the effect of the do while loop, simply check for your

Repeat string to certain length

戏子无情 提交于 2019-11-27 00:10:36
What is an efficient way to repeat a string to a certain length? Eg: repeat('abc', 7) -> 'abcabca' Here is my current code: def repeat(string, length): cur, old = 1, string while len(string) < length: string += old[cur-1] cur = (cur+1)%len(old) return string Is there a better (more pythonic) way to do this? Maybe using list comprehension? Jason Scheirer def repeat_to_length(string_to_expand, length): return (string_to_expand * ((length/len(string_to_expand))+1))[:length] For python3: def repeat_to_length(string_to_expand, length): return (string_to_expand * (int(length/len(string_to_expand))+1

Is there a regex flavor that allows me to count the number of repetitions matched by the * and + operators?

寵の児 提交于 2019-11-26 23:16:35
Is there a regex flavor that allows me to count the number of repetitions matched by the * and + operators? I'd specifically like to know if it's possible under the .NET Platform. You're fortunate because in fact .NET regex does this (which I think is quite unique). Essentially in every Match , each Group stores every Captures that was made. So you can count how many times a repeatable pattern matched an input by: Making it a capturing group Counting how many captures were made by that group in each match You can iterate through individual capture too if you want! Here's an example: Regex r =

Matlab - building a matrix by merging the same raw vector multiple times

橙三吉。 提交于 2019-11-26 23:16:17
问题 Is there a matlab function which allows me to do the following operation? x = [1 2 2 3]; and then based on x I want to build the matrix m = [1 2 2 3; 1 2 2 3; 1 2 2 3; 1 2 2 3] 回答1: You are looking for the REPMAT function: x = [1 2 2 3]; m = repmat(x,4,1); You can also use indexing to repeat the rows: m = x(ones(4,1),:); or even outer-product: m = ones(4,1)*x; and also using BSXFUN: m = bsxfun(@times, x, ones(4,1)) 回答2: You could try using vertcat , like this: x = [1 2 2 3]; m = vertcat(x,x,x

Android - Running a background task every 15 minutes, even when application is not running

不羁岁月 提交于 2019-11-26 22:49:07
问题 I need to build a background task that runs every 10/15 minutes (doesn't really matter, either is good), even when the application is not running. How can I accomplish this? I can't seem the wrap my head around this. I read I could use some sort of runnable() functionality or use a background services or AlarmManager. I was thinking of a background service, since it also must be done when the application itself is not running. What is a better way of doing this and how could I do it? 回答1: You

Element-wise array replication according to a count [duplicate]

Deadly 提交于 2019-11-26 19:07:02
This question already has an answer here: Repeat copies of array elements: Run-length decoding in MATLAB 5 answers My question is similar to this one , but I would like to replicate each element according to a count specified in a second array of the same size. An example of this, say I had an array v = [3 1 9 4] , I want to use rep = [2 3 1 5] to replicate the first element 2 times, the second three times, and so on to get [3 3 1 1 1 9 4 4 4 4 4] . So far I'm using a simple loop to get the job done. This is what I started with: vv = []; for i=1:numel(v) vv = [vv repmat(v(i),1,rep(i))]; end I

Repeating each element of a numpy array 5 times

泪湿孤枕 提交于 2019-11-26 18:56:29
import numpy as np data = np.arange(-50,50,10) print data [-50 -40 -30 -20 -10 0 10 20 30 40] I want to repeat each element of data 5 times and make new array as follows: ans = [-50 -50 -50 -50 -50 -40 -40 ... 40] How can I do it? What about repeating the whole array 5 times? ans = [-50 -40 -30 -20 -10 0 10 20 30 40 -50 -40 -30 -20 -10 0 10 20 30 40 -50 -40 -30 -20 -10 0 10 20 30 40 -50 -40 -30 -20 -10 0 10 20 30 40 -50 -40 -30 -20 -10 0 10 20 30 40 .......] In [1]: data = np.arange(-50,50,10) To repeat each element 5 times use np.repeat : In [3]: np.repeat(data, 5) Out[3]: array([-50, -50,