null

Call a function only if a value is neither null nor undefined

谁都会走 提交于 2020-01-02 06:01:42
问题 When a button is clicked I check if something exists in a localstorage key as such: var a = localStorage.getItem('foo'); if (typeof a != 'undefined') { // Function } but if the key doesn't exists at all, it return null. How can I call if not undefined and not null do function , else return true(?) or continue? 回答1: JavaScript has a concept of falsy values... i.e. 0, null , undefined and an empty string. Because of this, you should be able to just check if a is "truthy" (i.e. not one of the

shared_ptr null pointer and assignment

爷,独闯天下 提交于 2020-01-02 05:54:22
问题 I want to use shared_ptr just like I'd use an actual pointer. I wanted to be able to do things like shared_ptr<int> a; a = new int(5); a = 0; shared_ptr<int> foo() return 0; but it is not implemented by default. I changed the source code of the shared_ptr of the boost library by adding template<class Y> void operator=( int i ) { reset(i); } template<class Y> void reset(int i) { this_type(i).swap(*this); } template<class Y> void operator=( Y * p ) { reset(p); } shared_ptr(int i): px(0), pn() {

How to combine (merge) similar columns to remove NULLs via JOIN

烂漫一生 提交于 2020-01-02 05:29:12
问题 Problem Brief: I have a superclass table called "Customers" and two child tables that inherit from Customers called "Person" and "Company". So that, Customer entity has a one-to-one relationship with "Person" or "Company". (a Customer can only be of "Person" or of "Company", but not of both) This is represented below: Customer Person Company +-------+------+------+ +-------+------+------+ +-------+------+------+ | cID| col2| col3| | cID| fname| sname| | cID| name| col3| +-------+------+------

Is it acceptable to return null from a factory constructor in Dart?

安稳与你 提交于 2020-01-02 04:36:06
问题 I've been writing some code in Dart. I really love the factory constructor, but I'm afraid that I'm abusing it's usefulness. In particular, when I write a value object class, I sometimes return null if the validation fails. class EmailAddress { static final RegExp _regex = new RegExp(...); final String _value; factory EmailAddress(String input) { return _regex.hasMatch(input) ? new EmailAddress._internal(input) : null; } const EmailAddress._internal(this._value); toString() => _value; } At

How do i know when a lambda expression is null

给你一囗甜甜゛ 提交于 2020-01-02 04:10:11
问题 I need to programatically check whether a nested property/function result in a lambda expression is null or not. The problem is that the null could be in any of the nested subproperties. Example. Function is: public static bool HasNull<T, Y>(this T someType, Expression<Func<T, Y>> input) { //Determine if expression has a null property } Use: person.HasNull(d=>d.addressdetails.Street) person.HasNull(d=>d.addressdetails[1].Street) person.HasNull(d=>d.addressdetails.FirstOrDefault().Street)

Null To Boolean IValueConverter not working

僤鯓⒐⒋嵵緔 提交于 2020-01-02 02:17:12
问题 How do I use an IValueConverter to convert nulls into booleans? I'm using wpf to try to display a bunch of boolean values (in checkboxes). When a new record is created, these values are null, and appear as 'indeterminate' in the checkboxes. I want the nulls to appear and save as 'false' values. I tried to create a NullToBoolean converter that takes null values from the database and displays them as false, and then saves them as false when the user hits save. (Essentially, I'm trying to avoid

Why are all my puts returning =>nil?

泪湿孤枕 提交于 2020-01-02 01:54:13
问题 I know this may seem like a really simple question, but it really bothers me that my puts keep generating "=> nil" and I scoured for an answer but could not find one. Thanks. puts 'blink ' *4 blink blink blink blink => nil 回答1: Because that is the return value of puts : puts(obj, ...) → nil Writes the given objects to ios as with IO#print. Writes a record separator (typically a newline) after any that do not already end with a newline sequence. If called with an array argument, writes each

[leetcode]Linked List Cycle II

落爺英雄遲暮 提交于 2020-01-02 01:12:51
比I麻烦点的就是找到循环开始点TAT I只是判断是否循环。要求不使用额外空间(不然hash就可以了 按I的思路,我们又慢指针S和快指针F。。。F走两步,S走一步。。。若有环,必定相遇。 画个图(很丑勿喷 假设在红色凸起的地方相遇了。 F走的路程应该是S的两倍 S = x + y F = x + y + z + y = x + 2y + z 2*S = F 2x+2y = x + 2y + z 得到x = z 也就是从head到环开始的路程 = 从相遇到环开始的路程 那么。。。只要S和F相遇了,我们拿一个从头开始走,一个从相遇的地方开始走 两个都走一步,那么再次相遇必定是环的开始节点! /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *detectCycle(ListNode *head) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be

Reverse Linked List

江枫思渺然 提交于 2020-01-02 01:10:31
1 class Solution { 2 public: 3 ListNode* reverseList(ListNode* head) { 4 if(head==NULL) 5 return head; 6 ListNode* pre=head; 7 ListNode* mid=head->next; 8 ListNode* tail; 9 head->next=NULL; 10 while(mid!=NULL) 11 { 12 tail=mid->next; 13 mid->next=pre; 14 pre=mid; 15 mid=tail; 16 } 17 return pre; 18 } 19 }; View Code 考虑链表为空的情况,解决方法可以是迭代改变每个节点的next指针 完整代码: 1 #include <iostream> 2 #include <string> 3 #include <vector> 4 #include <algorithm> 5 #include <map> 6 using namespace std; 7 typedef struct ListNode { 8 int val; 9 ListNode *next; 10 ListNode(int x) : val(x), next(NULL) {} 11 }ListNode; 12

空值处理

孤街浪徒 提交于 2020-01-01 22:47:03
l数据库中,一个列如果没有指定值,那么值就为null,这个null和C#中的null,数据库中的null表示“不知道”,而不是表示没有。因此select null+1结果是null,因为“不知道”加1的结果还是“不知道”。 lselect * from score where english = null ; lselect * from score where english != null ;都没有任何返回结果,因为数据库也“不知道”。 lSQL中使用is null、is not null来进行空值判断: select * from score where english is null ; select * from score where english is not null ; lISNULL ( check_expression , replacement_value ) 来源: https://www.cnblogs.com/hsha/p/4591262.html