Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions js/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
* @returns {any[]}
*/
function flatten(arr) {

// let result = [];
// for (let item of arr) {
// if (Array.isArray[item]) {
// result.push(flatten(item));
// }
// result.push(item);
// } return result;
// let flattened=arr.reduce((accumulator,currentValue)=>accumulator.concat(currentValue), []);
// return flattened;
let result = [];
for (let item of arr) {
if (Array.isArray[item]) {
result.push(...flatten(item));
}
result.push(item);
} return result;
}
console.log(flatten([[1,2,3,4],[1,[1,[1]]]])==[1,2,3,4,1,1,1])
console.log(flatten([[1, 2, 3, 4], [1, [1, [1]]]]) == [1, 2, 3, 4, 1, 1, 1])
11 changes: 8 additions & 3 deletions js/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
* @param {number} size
* @return {Array}
*/
var chunk = function(arr, size) {

var chunk = function (arr, size) {
let result = [];
for (i = 0; i < arr.length; i += size) {
result.push(arr.slice(i, i + size));
}
return result;
};
console.log(chunk([1,2,3,4,5], 1)==[[1],[2],[3],[4],[5]])
console.log(chunk([1, 2, 3, 4, 5], 1));
// console.log(chunk([1, 2, 3, 4, 5], 1) == [[1], [2], [3], [4], [5]])
32 changes: 32 additions & 0 deletions js/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,36 @@
*/
function hasStraightFlush(arr) {
// 返回 true 或 false

for (let item in arr) {
let counter1 = 0;
let counter2 = 0;
let counter3 = 0;
let counter4 = 0;
if (item <= 12) {
counter1++;
}
else if (12 < item <= 25) {
counter2++;
}
else if (25 < item <= 38) {
counter3++;
}
else if (38 < item <= 51) {
counter4++;
}

}

if (counter1 >= 5 || counter2 >= 5 || counter3 >= 5 || counter4 >= 5) {
let judge1 = true;
}
if (judge1) {
let result1 = arr.fliter((x) => item <= 12);
let result2 = arr.fliter((x) => 12 < item <= 25);
let result3 = arr.fliter((x) => 25 < item <= 38);
let result4 = arr.fliter((x) => 38 < item <= 51);
}


}
1 change: 1 addition & 0 deletions web/bianzu.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions web/huodong.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading