Check for repeated characters in a string Javascript
This will do: function isIsogram (str) { return !/(.).*\1/.test(str); }
This will do: function isIsogram (str) { return !/(.).*\1/.test(str); }
Use each argument: rep(c(1027, 1028, 1030, 1032, 1037), each = 6) # [1] 1027 1027 1027 1027 1027 1027 # [7] 1028 1028 1028 1028 1028 1028 # [13] 1030 1030 1030 1030 1030 1030 # [19] 1032 1032 1032 1032 1032 1032 # [25] 1037 1037 1037 1037 1037 1037 times argument: rep(c(1027, 1028, … Read more
Jason Scheirer’s answer is correct but could use some more exposition. First off, to repeat a string an integer number of times, you can use overloaded multiplication: >>> ‘abc’ * 7 ‘abcabcabcabcabcabcabc’ So, to repeat a string until it’s at least as long as the length you want, you calculate the appropriate number of repeats … Read more
There are a number of ways you could achieve this. Solution A: If the range of numbers isn’t large (let’s say less than 10), you could just keep track of the numbers you’ve already generated. Then if you generate a duplicate, discard it and generate another number. Solution B: Pre-generate the random numbers, store them … Read more
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, -50, -50, -50, -40, -40, -40, -40, -40, -30, -30, -30, -30, -30, -20, -20, -20, -20, -20, -10, -10, -10, -10, -10, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 20, 20, … Read more
reindex+ repeat df.reindex(df.index.repeat(df.persons)) Out[951]: code . role ..1 persons 0 123 . Janitor . 3 0 123 . Janitor . 3 0 123 . Janitor . 3 1 123 . Analyst . 2 1 123 . Analyst . 2 2 321 . Vallet . 2 2 321 . Vallet . 2 3 321 . Auditor … Read more
var helloWorldTimer = NSTimer.scheduledTimerWithTimeInterval(60.0, target: self, selector: Selector(“sayHello”), userInfo: nil, repeats: true) func sayHello() { NSLog(“hello World”) } Remember to import Foundation. Swift 4: var helloWorldTimer = Timer.scheduledTimer(timeInterval: 60.0, target: self, selector: #selector(ViewController.sayHello), userInfo: nil, repeats: true) @objc func sayHello() { NSLog(“hello World”) }
You missed the each= argument to rep(): R> n <- 3 R> rep(1:5, each=n) [1] 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 R> so your example can be done with a simple R> rep(1:8, each=20)
df <- data.frame(a = 1:2, b = letters[1:2]) df[rep(seq_len(nrow(df)), each = 2), ]
I’m a fan of the KRON function: >> a = 1:3; >> N = 3; >> b = kron(a,ones(1,N)) b = 1 1 1 2 2 2 3 3 3 You can also look at this related question (which dealt with replicating elements of 2-D matrices) to see some of the other solutions involving matrix … Read more