### With `Array.prototype.remove(item)`
Code is clean and concise.
``` js
if (array.remove(item)) {
// [item] was removed, do something here.
}
```
### Without `Array.prototype.remove(item)`
Code is verbose or duplicated (everyone has their own version of
`removeArrayItem`) => **WASTE**.
```
The problem with `Set` is that its `add` method returns `this` instead of
`boolean`. If `Set.prototype.add` returned `boolean`, I would have used `Set`.
That’s why in the `select` method of my sample code, I use a custom defined
method named `pushIfAbsent`. The actual type of `_values` is not `A
Consider the following function
``` js
/**
* Parses the locale sensitive string [value] into a number.
*/
export function parseNumber(
value: string,
locale: string = navigator.language
): number {
let decimalSeparator = decimalSeparators.get(locale);
if (!decimalSeparator) {
What JS needs is a [cascade
operator](https://esdiscuss.org/topic/cascade-operator). With this operator,
property accessors and methods can be effectively chained without requiring
methods to return `this`.
___
es-discuss mailing list
es-discuss@mozil
This operator should have been added years ago. It would enable many APIs to
return more appropriate results instead of `this`.
For example, `Set.prototype.add(value)` could return a boolean indicating if an
item was actually added instead of `this`.
The benefits are
- efficient (memory & speed)
- clear intent
- concise
There are always use cases where you want to mutate arrays.
How would you rewrite the following `deselect` method using `filter`?
``` js
export class Selector {
private _values: T[] = [];
get values(): ReadonlyArray
There are cases that you only want to remove the first occurrence of an item
(because you know there is at most one occurrence of that item) and there are
cases that you want to remove more than one item. Therefore, I propose adding
the following methods (written in TypeScript here for static ty
7 matches
Mail list logo