Skip to content
This repository was archived by the owner on Sep 15, 2020. It is now read-only.

Commit ce999e5

Browse files
Convert word counts from array to object
1 parent f0a6148 commit ce999e5

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/components/Terms.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { PropTypes } from 'react'
33
export class Terms extends React.Component {
44

55
static propTypes = {
6-
terms: PropTypes.arrayOf(PropTypes.array).isRequired
6+
terms: PropTypes.arrayOf(PropTypes.object).isRequired
77
}
88
static defaultProps = {
99
terms: []
@@ -22,13 +22,12 @@ export class Terms extends React.Component {
2222

2323
componentWillMount () {
2424
this.shuffleArray(this.props.terms)
25-
console.log(this.props.terms)
2625
}
2726

2827
render () {
2928
return (<div className=''>
3029
<div className='text-center'>
31-
{this.props.terms.map((term) => <p key={term[0]}>{term[0]}</p>)}
30+
{this.props.terms.map((term) => <p key={term.word}>{term.word}</p>)}
3231
</div>
3332
</div>)
3433
}

src/redux/utils/terms.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export const getTopTerms = (tweets: Array): Array => {
3434
let count = counts.get(word) || 0
3535
counts.set(word, count + 1)
3636
})
37-
// Sort words by counts
38-
let ret = Array.from(counts.entries())
39-
ret.sort((a, b) => b[1] - a[1])
37+
// Sort words by counts, descending
38+
let ret = Array.from(counts.entries()).map(([word, count]) => ({word, count}))
39+
ret.sort((a, b) => b.count - a.count)
4040
// Return only top 10 terms
4141
ret = ret.slice(0, 10)
4242
return ret

src/views/TwitterView/TwitterView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class TwitterView extends React.Component {
2323
getTweets: PropTypes.func.isRequired,
2424
tweets: PropTypes.arrayOf(PropTypes.string).isRequired,
2525
screenName: PropTypes.string,
26-
topTerms: PropTypes.arrayOf(PropTypes.array).isRequired
26+
topTerms: PropTypes.arrayOf(PropTypes.object).isRequired
2727
}
2828

2929
componentWillMount () {

0 commit comments

Comments
 (0)