Files

2.5 KiB

title
title
Size of the Set

Size of the Set

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :pencil:

:checkered_flag: Problem Explanation:

To solve this problem, you have to write a function for the class that returns the size of the set.

:speech_balloon: Hint: 1

Create a size function in the Set class.

try to solve the problem now

:speech_balloon: Hint: 2

Use the length attribute on the values of the Set.

try to solve the problem now

Spoiler Alert!

warning sign

Solution ahead!

:beginner: Basic Code Solution:

this.size = function()
{
    return this.values().length;
}

:rocket: Run Code

Code Explanation:

  • The number of items is achieved by attaining the collection using the "values" function and getting the length attribute of it.

:clipboard: NOTES FOR CONTRIBUTIONS:

  • :warning: DO NOT add solutions that are similar to any existing solutions. If you think it is similar but better, then try to merge (or replace) the existing similar solution.
  • Add an explanation of your solution.
  • Categorize the solution in one of the following categories — Basic, Intermediate and Advanced. :traffic_light: