Skip to content

Instantly share code, notes, and snippets.

@Summonshr
Created February 7, 2019 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Summonshr/11ddfab26a680c4378d014584de1717d to your computer and use it in GitHub Desktop.
Save Summonshr/11ddfab26a680c4378d014584de1717d to your computer and use it in GitHub Desktop.
Show how you can leverage Laravel Collections to create an elegant solution to the following problem. Create a function that accepts a GitHub username, and returns that users "Score" based on the below rules. The information can be retrieved using GitHub's public api
import React, { Component } from 'react';
import { render } from 'react-dom';
import Hello from './Hello';
import './style.css';
import axios from 'axios';
import lodash from 'lodash';
const url = 'https://api.github.com/users/:username/events/public';
const criteria = {
PushEvent :10,
PullRequestEvent:5,
IssueCommentEvent:4,
}
class App extends Component {
constructor() {
super();
this.state = {
name: 'summonshr',
response:[]
};
}
update(){
axios.get(url.replace(':username', this.state.name))
.then(response=>this.setState({response:response.data}));
}
getScore(response){
return JSON.stringify(_.reduce(_.mapValues(_.groupBy(response,'type'),(e,k)=>console.log(k) || e.length * ( criteria[k] || 1)),(c,r)=>c+r, 0))
}
render() {
return (
<div style={{display:'grid', gridGap: '20px', gridTemplateColumns: '1fr 1fr 1fr'}}>
<input value={this.state.name} onChange={event=>this.setState({name: event.target.value})}/>
<button onClick={this.update.bind(this)}>Score</button>
{this.getScore(this.state.response)}
</div>
);
}
}
render(<App />, document.getElementById('root'));
Show how you can leverage Laravel Collections to create an elegant solution to the following problem. Create a function that accepts a GitHub username, and returns that users "Score" based on the below rules. The information can be retrieved using GitHub's public api (https://api.github.com/users/:username/events/public). Upload your answer to a private gist (https://gist.github.com/) and share the URL.
PushEvent = 10 points.
PullRequestEvent = 5 points.
IssueCommentEvent = 4 points.
Any other event = 1 point
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment