Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 76ef555

Browse files
authored
Added Creating array with ascending integers
1 parent 8c29267 commit 76ef555

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎README.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,6 +2458,23 @@ function mostCommonWord(inputString) {
24582458
return mostCommonWord;
24592459
}
24602460
```
2461+
### Creating array with ascending integers
2462+
You can use `Array.from()` to map, if you provide a mapping function as its second parameter.
2463+
```
2464+
Array.from(new Array(3), (x, i) => i)
2465+
// [ 0, 1, 2 ]
2466+
```
2467+
Creating an arbitrary range of integers:
2468+
```
2469+
const START = 2, END = 5;
2470+
Array.from(new Array(END - START), (x, i) => i + START)
2471+
// [ 2, 3, 4 ]
2472+
```
2473+
Another way of creating an Array with ascending integers is via `.keys()`, which also treats holes as if they were `undefined` elements:
2474+
```
2475+
[...new Array(3).keys()]
2476+
// [ 0, 1, 2 ]
2477+
```
24612478
### Brackets match
24622479
For the given string, determine if the strings of brackets in the input is valid or invalid by these criteria.
24632480
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /