18 lines
489 B
Plaintext
18 lines
489 B
Plaintext
![]() |
Using <code>[Int]().count</code> to test for emptiness works, but using <code>[Int]().isEmpty</code> makes the code more readable and can be more performant. The time complexity of any <code>isEmpty</code> implementation should be <code>O(1)</code> whereas some implementations of <code>count()</code> can be <code>O(n)</code>.
|
||
|
|
||
|
== Noncompliant Code Example
|
||
|
|
||
|
----
|
||
|
if (arr.count == 0) { // Noncompliant
|
||
|
/* ... */
|
||
|
}
|
||
|
----
|
||
|
|
||
|
== Compliant Solution
|
||
|
|
||
|
----
|
||
|
if (arr.isEmpty) {
|
||
|
/* ... */
|
||
|
}
|
||
|
----
|