Changed type definition for once()

This commit is contained in:
fkereki
2018-03-31 01:20:26 -03:00
parent b30b89aa78
commit 6d7830ea98
2 changed files with 26 additions and 2 deletions
+2 -2
View File
@@ -1,9 +1,9 @@
/* @flow */ /* @flow */
type genericFunction = (...args: Array<mixed>) => mixed; type genericFunction = (...args: Array<mixed>) => mixed;
type higherOrderFunction = genericFunction => genericFunction; type voidFunction = (...args: Array<mixed>) => void;
const once: higherOrderFunction = (fn: genericFunction) => { const once = (fn: genericFunction): voidFunction => {
let done = false; let done = false;
return (...args) => { return (...args) => {
if (!done) { if (!done) {
+24
View File
@@ -0,0 +1,24 @@
/* @flow */
/* eslint-disable no-unused-vars */
let values = [22, 9, 60, 12, 4, 56];
const maxOfValues = Math.max(...values); // 60
const minOfValues = Math.min(...values); // 4
let arr1 = [1, 1, 2, 3];
let arr2 = [13, 21, 34];
let copyOfArr1 = [...arr1];
let fibArray = [0, ...arr1, 5, 8, ...arr2]; // the first 10 Fibonacci numbers
let person = { name: "Juan", age: 24 };
let copyOfPerson = { ...person };
let expandedPerson = { ...person, sister: "María" };
const average = (...nums: Array<number>): number => {
let sum = 0;
for (let i = 0; i < nums.length; i++) {
sum += nums[i];
}
return sum / nums.length;
};
console.log(average(22, 9, 60, 12, 4, 56)); // 27.166667