Skip to content

Commit 090811a

Browse files
committed
count characters: done
1 parent 0fd89c6 commit 090811a

File tree

1 file changed

+1
-17
lines changed
  • count_characters_in_your_string

1 file changed

+1
-17
lines changed
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
function count(string) {
2-
const test = undefined;
3-
console.log(!!test + 1);
4-
return string.split('').reduce((acc, cur) => (acc[cur] += !!acc[cur] + 1, acc), {});
5-
6-
// const result = {};
7-
// const split = string.split('');
8-
// if(split.length) {
9-
// for(let i = 0; i < split.length; i++) {
10-
// if(result[split[i]]) {
11-
// result[split[i]] += 1;
12-
// }
13-
// else {
14-
// result[split[i]] = 1;
15-
// }
16-
// }
17-
// }
18-
// return result;
2+
return string.split('').reduce((acc, cur) => (acc[cur] ? acc[cur]++ : acc[cur] = 1, acc), {});
193
}
204

215
module.exports = count;

0 commit comments

Comments
 (0)