range

Javascript array of ranges reduction

一世执手 提交于 2019-12-01 09:25:37
What is the best possible way to reduce an array of ranges in javascript. For example I have 1-3,4-5,10-12,2-4 the result I need for this is 1-5, 10-12 What is the best way to tackle this problem ? I would first create another array with no duplicates, storing the numbers that are covered by the ranges: 1-3 covers 1, 2, 3 --> [1, 2, 3] 4-5 covers 4, 5 --> [1, 2, 3, 4, 5] 10-12 covers 10, 11, 12 --> [1, 2, 3, 4, 5, 10, 11, 12] 2-4 covers 2, 3, 4 --> [1, 2, 3, 4, 5, 10, 11, 12] Then, sort the array: [1, 2, 3, 4, 5, 10, 11, 12] // nothing changed in this example Finally, rebuild the ranges,

NULL vs. `infinity` in PostgreSQL range types

China☆狼群 提交于 2019-12-01 07:54:41
What is the meaning of 'infinity' in PostgreSQL range types? Is there any difference between specifying infinity or -infinity as a bound, or NULL ? I.e. is infinity an explicit form of specifying that the range bound is infinite, whereas NULL would implicit specify an infinite bound range? See the following examples: SELECT tstzrange('-infinity','infinity') && tstzrange(NULL, NULL); ?column? ---------- t SELECT tstzrange('2013-01-01 00:00:00+01', '2013-02-01 00:00:00+01') && tstzrange(NULL, '2013-03-01 00:00:00+01'); ?column? ---------- t SELECT tstzrange('2013-01-01 00:00:00+01', '2013-02-01

Does range() not evaluate its argument every time?

ⅰ亾dé卋堺 提交于 2019-12-01 07:24:25
问题 l is passed as an argument to range function whose value is modified inside for loop, but the loop is going for 10 times instead of 5 . i = 0 l = 10 for i in range(l): print i,l l = l-1 The output is 0 10 1 9 2 8 3 7 4 6 5 5 6 4 7 3 8 2 9 1 While I expected 0 10 1 9 2 8 3 7 4 6 Does range() evaluates value for the first time only or something else is the reason? 回答1: No, the for loop evaluates the iterable expression just once. range() is called once , and the for loop then iterates over the

Div “contenteditable” : get and delete word preceding caret

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 07:08:00
Thanks to this question and answer posted by Tim Down, I made a function to get the word preceding caret in a "contenteditable" div. Here's a fiddle , and here's the function: function getWordPrecedingCaret (containerEl) { var preceding = "", sel, range, precedingRange; if (window.getSelection) { sel = window.getSelection(); if (sel.rangeCount > 0) { range = sel.getRangeAt(0).cloneRange(); range.collapse(true); range.setStart(containerEl, 0); preceding = range.toString(); } } else if ((sel = document.selection) && sel.type != "Control") { range = sel.createRange(); precedingRange = range

Javascript array of ranges reduction

早过忘川 提交于 2019-12-01 06:43:52
问题 What is the best possible way to reduce an array of ranges in javascript. For example I have 1-3,4-5,10-12,2-4 the result I need for this is 1-5, 10-12 What is the best way to tackle this problem ? 回答1: I would first create another array with no duplicates, storing the numbers that are covered by the ranges: 1-3 covers 1, 2, 3 --> [1, 2, 3] 4-5 covers 4, 5 --> [1, 2, 3, 4, 5] 10-12 covers 10, 11, 12 --> [1, 2, 3, 4, 5, 10, 11, 12] 2-4 covers 2, 3, 4 --> [1, 2, 3, 4, 5, 10, 11, 12] Then, sort

Check if a date within in range

╄→гoц情女王★ 提交于 2019-12-01 06:12:17
I am trying to check if a date of format mm.dd.yyyy is greater than today and less than the date after 6 months from today. Here is my code: var isLinkExpiryDateWithinRange = function(value) { var monthfield = value.split('.')[0]; var dayfield = value.split('.')[1]; var yearfield = value.split('.')[2]; var inputDate = new Date(yearfield, monthfield - 1, dayfield); var today = new Date(); today = new Date(today.getFullYear(), today.getMonth(), today.getDate()); alert(inputDate > today);//alert-> true var endDate = today; endDate.setMonth(endDate.getMonth() + 6); alert(inputDate > today);//alert

Printing all contents EXCEPT matching range pattern using awk

ぃ、小莉子 提交于 2019-12-01 05:59:57
In Awk, the range pattern is not an expression, so canot use the "!" to not it. so how to implement it (Printing all contents EXCEPT matching range pattern using awk)? e.g. $cat 1.t abd hfdh # fafa deafa 123 # end the result I wanted: cat 1.t abd hfdh end EDIT: I gave an impertinent example. the endpattern should be different with the startpattern because I just have not test this. That's My fault. At the same time, I want to operate the range pattern and the not range pattern differently. So sed is not my choice. you just gave a tricky (I don't know I should call it good or bad ^_^ ) example.

scala Range for Long

坚强是说给别人听的谎言 提交于 2019-12-01 05:40:09
I'm new to the Scala language. I need Range for Long type. I need a List of [1, 2, 3 ... 10000000] with step 1. If I use until/to I get an error because of using Long instead of Int. I try to write simple function which expects a start, an end and and an empty List and generates a List of [start .. end]. Here is my function: def range_l(start : Long, end : Long, list : List[Long]) : List[Long] = { if (start == end){ val add_to_list = start :: list return add_to_list } else { val add_to_list = start :: list range_l(start + 1, end, add_to_list) } } If I call it like: range_l(1L, 1000000L, List()

Python range( ) is not giving me a list [duplicate]

主宰稳场 提交于 2019-12-01 05:17:43
This question already has an answer here: Python 3 turn range to a list 8 answers Having a beginner issue with Python range. I am trying to generate a list, but when I enter: def RangeTest(n): # list = range(n) return list print(RangeTest(4)) what is printing is range(0,4) rather than [0,1,2,3] What am I missing? Thanks in advance! TerryA You're using Python 3, where range() returns an "immutable sequence type" instead of a list object (Python 2). You'll want to do: def RangeTest(n): return list(range(n)) If you're used to Python 2, then range() is equivalent to xrange() in Python 2. By the

NULL vs. `infinity` in PostgreSQL range types

走远了吗. 提交于 2019-12-01 05:08:48
问题 What is the meaning of 'infinity' in PostgreSQL range types? Is there any difference between specifying infinity or -infinity as a bound, or NULL ? I.e. is infinity an explicit form of specifying that the range bound is infinite, whereas NULL would implicit specify an infinite bound range? See the following examples: SELECT tstzrange('-infinity','infinity') && tstzrange(NULL, NULL); ?column? ---------- t SELECT tstzrange('2013-01-01 00:00:00+01', '2013-02-01 00:00:00+01') && tstzrange(NULL,