Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f0faa03

Browse files
authored
Update README.md
1 parent bc042c8 commit f0faa03

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

‎README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
1. [Important Methods](#methods)
77

88
## Methods
9-
> Most important javascript build in methods
9+
> Hello Javascript
1010
1111
<a name="typeof"></a><a name="1.1"></a>
1212
- [1.1](#typeof) **typeof**: Returns the type.
@@ -118,8 +118,30 @@ console.log(user); // TypeError: Cannot assign to read only property 'age' of ob
118118
```
119119

120120
<a name="rename"></a><a name="1.7"></a>
121-
- [1.5](#rename) **rename**: Rename multiple files extentions at once by a command (Just for Win).
121+
- [1.7](#rename) **rename**: Rename multiple files extentions at once by a command (Just for Win).
122122

123123
```javascript
124124
Get-ChildItem *.css | Rename-Item -NewName { $_.name -Replace '\.css','.scss' }
125125
```
126+
127+
<a name="majority"></a><a name="1.8"></a>
128+
- [1.8](#majority) **majority**: Find Majority Element.
129+
130+
```javascript
131+
function majorityElement(arr) {
132+
let count = 0, candidate = null;
133+
134+
for (let num of arr) {
135+
if (count === 0) candidate = num;
136+
count += (num === candidate) ? 1 : -1;
137+
}
138+
139+
return candidate;
140+
}
141+
142+
// Time complexity: O(n)
143+
// Space complexity: O(1)
144+
145+
const arr = [3, 2, 3, 4, 3, 1, 6, 6, 7, 8, 6, 9, 6];
146+
console.log(majorityElement(arr)); // Output: 6
147+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /