-
Notifications
You must be signed in to change notification settings - Fork 1
/
divideArray.js
54 lines (51 loc) · 1.32 KB
/
divideArray.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const divideArray = (arr)=>{
let chunkArray = []
let chunkSize = 3;
for(let i=0; i<arr.length; i+=chunkSize){
let chunk = arr.slice(i, i + chunkSize);
chunkArray.push(chunk)
}
let resArray = []
for(let i=0; i<chunkArray.length; i++){
if(Array.isArray(chunkArray[i])){
resArray.push(chunkArray[i].reverse())
}
}
return resArray
}
console.log(divideArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
// function firstUniqueChar(str) {
// const charCount = {};
// for (let char of str) {
// charCount[char] = charCount[char] + 1 || 1;
// }
// for (let char of str) {
// if (charCount[char] === 1) {
// return char;
// }
// }
// return null;
// }
// const str = "leetcode";
// const result = firstUniqueChar(str);
// console.log(result); // Output: "l"
function maxOccurrenceChar(str){
let charCount = {}
for(let i=0; i<str.length; i++){
let char = str[i];
if(char !==' '){
charCount[char] = charCount[char] + 1 || 1;
}
}
let max = 0
let c;
for(let [key] in charCount){
if(charCount[key] > max){
c+=key
max = charCount[key];
}
}
console.log(c)
return `${c, max}`
}
console.log(maxOccurrenceChar("Hello World"))