range

What kind of type have the range in for loop?

五迷三道 提交于 2019-12-21 20:35:06
问题 When we write the following: for i in 1...10 { //do stuff } I want know what type have the range 1...10 to use it in function call for example: myFunc(1...10) 回答1: If you put a breakpoint after defining let range = 1..<10 , you will see that it's actually not a Range structure, but rater a CountableRange (or CountableClosedRange for 0...10) Docs: CountableRange, CountableClosedRange Functions: func printRange(range: CountableRange<Int>) { for i in range { print ("\(i)") } } func printRange

How to count the number of uppercase characters in a NSString?

狂风中的少年 提交于 2019-12-21 19:27:29
问题 I'm trying to find out the best way to count the number of uppercase characters that are in a NSString. I know how to find out if a certain character is uppercase by using this code: NSString *s = @"This is a string"; BOOL isUppercase = [[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:[s characterAtIndex:0]]; What would be the best way to count the number of uppercase letters in a NSString? Thanks. 回答1: NSString *s = @"This is a string"; int count=0; for (i = 0; i < [s length];

Plot 'ranges' of variable in data

余生颓废 提交于 2019-12-21 19:14:32
问题 I have observations in the form of ranges For eg: A 13-20, B 15-30, C 23-40, D 2-11 I want to plot them in R in form of the starting value and the end value for eg. 13 and 20 for A(upper and lower limits if you may say) in order to visualize and find out what ranges are common to certain combinations of observations. Is there a quick way to do this in R ? I think this is a very trivial problem I am having but I cant think of anyway to do it right now. 回答1: Here is a solution using ggplot . It

R overlap multiple GRanges with findOverlaps()

主宰稳场 提交于 2019-12-21 17:54:18
问题 I have three tables with differing genomic intervals. Here is an example: > a chr interval.start interval.end names 1 chr1 5 10 a 2 chr1 6 10 b 3 chr2 7 10 c 4 chr3 8 10 d > b chr interval.start interval.end names 1 chr1 6 15 e 2 chr1 7 15 f 3 chr1 8 15 g > c chr interval.start interval.end names 1 chr1 7 12 h 2 chr1 8 12 i 3 chr5 9 12 j 4 chr10 10 12 k 5 chr20 11 12 l I am trying to find the common intervals between all tables after converting info to GRanges. Essentially I want to do

MySQL - select one row - then one next and one previous relative to the selected

限于喜欢 提交于 2019-12-21 15:16:57
问题 I'll try to make this clear. I need to select a specific row and one row previous relative from that selected row and one row next relative from that selected row without using id's. Is this possible? Previous and next one, in short. The reason why I can't (maybe I just don't know how) use id's, is because they are not in sequential order. They have gaps as you can see from this rather immature and random example. TABLE <-the name of the table +----+----------------------+-------+ | id | name

Difference between two ranges

给你一囗甜甜゛ 提交于 2019-12-21 12:33:06
问题 I can find plenty of questions and example regarding the 'Union' and 'Intersect' VBA methods but I can't find anything much regarding a 'Set Difference' method? Does this exist (other than by using combinations of union and intersect)?. I'm trying to find a simple way of getting all of range1 excluding any of range1 that overlaps range2 without knowing the size or shape of either range. Any help would be greatly appreciated. EDIT. Attempted solution where rng1 is the red section and rng2 is

Convert arbitrary length to a value between -1.0 a 1.0?

微笑、不失礼 提交于 2019-12-21 12:24:01
问题 How can I convert a length into a value in the range -1.0 to 1.0? Example: my stage is 440px in length and accepts mouse events. I would like to click in the middle of the stage, and rather than an output of X = 220 , I'd like it to be X = 0 . Similarly, I'd like the real X = 0 to become X = -1.0 and the real X = 440 to become X = 1.0 . I don't have access to the stage, so i can't simply center-register it, which would make this process a lot easier. Also, it's not possible to dynamically

How to count by twos with Python's 'range'

不打扰是莪最后的温柔 提交于 2019-12-21 07:05:05
问题 So imagine I want to go over a loop from 0 to 100, but skipping the odd numbers (so going "two by two"). for x in range(0,100): if x%2 == 0: print x This fixes it. But imagine I want to do so jumping two numbers? And what about three? Isn't there a way? 回答1: Use the step argument (the last, optional): for x in range(0, 100, 2): print x Note that if you actually want to keep the odd numbers, it becomes: for x in range(1, 100, 2): print x Range is a very powerful feature . 回答2: (Applicable to

Range of Years in JavaScript for a select box

你说的曾经没有我的故事 提交于 2019-12-21 03:21:15
问题 I'm trying to create a dynamic select box in JavaScript with a range of years starting with 'some' year and ending with the current year. Is there anything like Ruby's range class in JavaScript or do I have to loop trough the years using a for loop? Here's what I've come up with though I think it's a bit much considering in Ruby I can just use a range. this.years = function(startYear){ startYear = (typeof(startYear) == 'undefined') ? 1980 : startYear var currentYear = new Date().getFullYear()

swift convert Range<Int> to [Int]

亡梦爱人 提交于 2019-12-20 15:36:57
问题 how to convert Range to Array I tried: let min = 50 let max = 100 let intArray:[Int] = (min...max) get error Range<Int> is not convertible to [Int] I also tried: let intArray:[Int] = [min...max] and let intArray:[Int] = (min...max) as [Int] they don't work either. 回答1: You need to create an Array<Int> using the Range<Int> rather than cast ing it. let intArray: [Int] = Array(min...max) 回答2: Put the Range in the init. let intArray = [Int](min...max) 回答3: do: let intArray = Array(min...max) This