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 07daf5f

Browse files
feat: add problems
1 parent b2019bd commit 07daf5f

8 files changed

+109
-0
lines changed

‎BFE.dev/10. first bad version.js

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @param {Function} func
3+
* @param {number} wait
4+
*/
5+
function throttle(func, wait) {
6+
let waiting;
7+
let params;
8+
9+
function callback() {
10+
if (params) {
11+
func(...params);
12+
params = null;
13+
}
14+
}
15+
16+
return function (...args) {
17+
params = args;
18+
if (!waiting) {
19+
callback();
20+
}
21+
22+
waiting = setTimeout(() => {
23+
waiting = null;
24+
callback();
25+
}, wait);
26+
};
27+
}

‎BFE.dev/5. implement throttle() with leading & trailing option.js

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @param {Function} func
3+
* @param {number} wait
4+
*/
5+
function debounce(func, wait) {
6+
let timer;
7+
return function (...args) {
8+
clearTimeout(timer);
9+
timer = setTimeout(() => {
10+
func(...args);
11+
timer = null;
12+
}, wait);
13+
};
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {Function} func
3+
* @param {number} wait
4+
* @param {boolean} option.leading
5+
* @param {boolean} option.trailing
6+
*/
7+
function debounce(func, wait, option = { leading: false, trailing: true }) {
8+
let timer;
9+
let lastArgs;
10+
return function betterFunction(...args) {
11+
lastArgs = args;
12+
clearTimeout(timer);
13+
if (option.leading && !timer && lastArgs) {
14+
func(...lastArgs);
15+
lastArgs = null;
16+
}
17+
timer = setTimeout(() => {
18+
if (option.trailing && lastArgs) {
19+
func(...lastArgs);
20+
}
21+
timer = null;
22+
}, wait);
23+
};
24+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @param {any[]} arr
3+
*/
4+
function shuffle(arr) {
5+
for (let i = 0; i < arr.length; i++) {
6+
const j = i + Math.floor(Math.random() * (arr.length - i));
7+
[arr[i], arr[j]] = [arr[j], arr[i]];
8+
}
9+
}

‎BFE.dev/9. decode message.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {string[][]} message
3+
* @return {string}
4+
*/
5+
function decode(message) {
6+
let ans = "";
7+
let i = 0;
8+
let j = 0;
9+
let direction = 1;
10+
while (j < message.length && i < message[0].length) {
11+
ans += message[j][i];
12+
i++;
13+
if (j === 0) {
14+
direction = 1;
15+
}
16+
if (j + 1 === message.length) {
17+
direction = -1;
18+
}
19+
j += direction;
20+
}
21+
return ans;
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @param {string[]} emails
3+
* @return {number}
4+
*/
5+
var numUniqueEmails = function (emails) {
6+
const uniqueEmails = {};
7+
emails.forEach(email => {
8+
const [username, domainName] = email.split("@");
9+
uniqueEmails[`${username.split("+")[0].replaceAll(".", "")}@${domainName}`] = 1;
10+
});
11+
12+
return Object.keys(uniqueEmails).length;
13+
};

0 commit comments

Comments
(0)

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