-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27691d8
commit ff041ce
Showing
5 changed files
with
47 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Copyright (c) 2019-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
*/ | ||
|
||
declare function flatMap<T, U>( | ||
list: $ReadOnlyArray<T>, | ||
fn: (item: T, index: number) => $ReadOnlyArray<U> | U, | ||
): Array<U>; | ||
|
||
/* eslint-disable no-redeclare */ | ||
// $FlowFixMe | ||
const flatMap = Array.prototype.flatMap | ||
? function(list, fn) { | ||
// $FlowFixMe | ||
return Array.prototype.flatMap.call(list, fn); | ||
} | ||
: function(list, fn) { | ||
let result = []; | ||
for (let i = 0; i < list.length; i++) { | ||
const value = fn(list[i]); | ||
if (Array.isArray(value)) { | ||
result = result.concat(value); | ||
} else { | ||
result.push(value); | ||
} | ||
} | ||
return result; | ||
}; | ||
export default flatMap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters