Skip to content

Commit

Permalink
20241011
Browse files Browse the repository at this point in the history
  • Loading branch information
russhustle committed Oct 11, 2024
1 parent a747806 commit 442b62f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 11 deletions.
24 changes: 13 additions & 11 deletions docs/hash/hash_map.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,23 @@

- Return the indices of the two numbers such that they add up to a specific target.

```python linenums="1"
--8<-- "0001_two_sum.py"
```
=== "Python"

C++
```python linenums="1"
--8<-- "0001_two_sum.py"
```

```cpp linenums="1"
--8<-- "cpp/0001_two_sum.cpp"
```
=== "C++"

JavaScript
```cpp linenums="1"
--8<-- "cpp/0001_two_sum.cpp"
```

```javascript
--8<-- "js/0001_two_sum.js"
```
=== "JavaScript"

```javascript
--8<-- "js/0001_two_sum.js"
```

## 409. Longest Palindrome

Expand Down
44 changes: 44 additions & 0 deletions docs/javascript/hashmap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 1. Create a new HashMap
let hashMap = new Map();
console.log(hashMap);

// 2. Add key-value pairs
hashMap.set("apple", 1); // Adds key 'apple' with value 1
hashMap.set("banana", 2);
hashMap.set("cherry", 3);

console.log(hashMap);

// 3. Get a value by its key
console.log(hashMap.get("apple"));
// Output: 1

// 4. Check if a key exists
console.log(hashMap.has("banana"));
// Output: true

console.log(hashMap.has("grape"));
// Output: false

// 5. Delete a key-value pair
hashMap.delete("banana");
console.log(hashMap);

// 6. Get the size of the HashMap
console.log(hashMap.size);
// Output: 2

// 7. Loop through the HashMap
hashMap.forEach((value, key) => {
console.log(key, ":", value);
});

// 8. Check if HashMap is empty
console.log(hashMap.size === 0);
// Output: false

// 9. Clear the HashMap (remove all key-value pairs)
hashMap.clear();
console.log(hashMap);
console.log(hashMap.size);
// Output: 0

0 comments on commit 442b62f

Please sign in to comment.