100 JS Functions

Beginner

1. minutesToHours

2. averageOf4Numbers

3. concat3

4. max5

5. getMonthsNeededToWait

6. getGasolineAmount

7. lastNRevert

8. getBusinessAddress

9. getUserObject

10. canDriveCar

11. areAllNumbersEven

12. getBiggestNumberInArrays

13. getLongestString

14. everyNPositions

15. doubleNumbers

16. mostRepetitions

17. getMillisecondsBetween

18. getMonthOfTheYear

19. addDays

20. getDevelopers

21. extractElementsBetweenPositions

22. isSorted

23. halfAndHalf

24. isSameDay

25. getMaxMovingDistance

Intermediate

26. arrayToObject

27. pickFields

28. getHighestPaidEmployee

29. flipObject

30. diffArrays

31. countPageViews

32. linkedNumbersSum

33. getMissingContacts

34. removeFirstAndLast

35. biggestPowerOf2

36. areValuesUnique

37. fetchGitHubName

38. rotateArray

39. getDaysInMonth

40. formatDateTime

41. toDecimal

42. compareSets

43. groupBirthdays

44. diffReactions

45. rgbToHex

46. timeAgo

47. customArraySort

48. moveItems

49. isValidPassword

50. mergeSortedArrays

51. ascendingSplit

52. findUniqueNumber

53. parseQueryParams

54. simpleCompression

55. partitionArray

56. findFreeCalendarSpots

57. mergeIntervals

58. simpleURLParser

59. pickNested

60. fetchNamesOfAllPublicRepos

61. getPaginatedData

62. getCheckPassword

63. getAdd5

64. getAddN

65. fetchClosedPullRequests

66. fetchBranchNames

67. searchMessages

68. objectToMap

69. createQueue

70. createStack

71. isSameWeek

72. bfsTraversal

73. dfsTraversal

74. getDoubleN

75. deepCopy

Advanced

76. uniqBy

77. flow

78. createCounter

79. createPromise

80. reverseForEach

81. checkSettlesInTime

82. sorted

83. groupBy

84. createLinkedList

85. promiseOrder

86. isDeepEqual

87. delayResolve

88. classInheritance

89. customBind

90. todoList

91. reverseReduce

92. withCount

93. maxInvocations

94. createObservable

95. createPubSub

96. cacheGetResult

97. currySum

98. getCurry

99. throttle

100. debounce

77.flow

Write a function named flow that receives one or more parameters

  • each of them a pure function

The function should return a new function - let's call it run - that will receive one or more parameters. It will successively invoke the pure functions, in order, passing the result of the previous invocation as the argument to the next one.

The run function will return the result of the last pure function invocation.

The first pure function should receive as parameters all the parameters received by run.

Example 1

const add = (a, b) => a + b;
const square = (a) => a ** 2;

const run = flow(add, square, square);

console.log(run(1, 2)); // 81

/**
 * We first invoke the `add` with (1, 2) as parameters,
 * which returns 3.
 * 
 * We then take this result and pass it to the `square`
 * function, which returns 9.
 * 
 * Finally, we pass this result to the `square` function
 * again, and get 81.
 */

You'll see test results here!