Skip to content

Latest commit

 

History

History
42 lines (26 loc) · 1.32 KB

File metadata and controls

42 lines (26 loc) · 1.32 KB

Easy Problem Solution

Key Topics

Rest Parameters, Arguments Object

Problem In My Own Words

Create a function that returns the number of arguments that were passed to it, regardless of the argument types.

Final Solution

  • Time Complexity: O(1) since we're just accessing a length property
function argumentsLength(...args) {
	return args.length;
}

Process

The solution uses the rest parameter syntax ...args in order to collect all of the arguments into a single array and then, returns the length of that array using the length property on the args array.

Test Cases & Findings

argumentsLength(1, 2, 3); // 3
argumentsLength(['a', 'b'], 'c', 123, true); // 4

What I Learned

  • Using rest parameters to college arguments into an array

Resources