Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let character = {};
- updateCharacter = (path, value) => {
- character[path] = value;
- }
- const Character = function() {
- this.moves = [];
- this.firstName = ''
- this.lastName = ''
- this.getName = () => `${this.firstName} ${this.lastName}`;
- this.setFirstName = name => this.firstName = name;
- this.setLastName = name => this.lastName = name;
- this.addMove = (name, notatian) => {
- this.moves.push({ name, notatian });
- }
- this.toString = () => JSON.stringify({
- name: this.getName(),
- firstName: this.firstName,
- lastName: this.lastName,
- moves: this.moves,
- })
- };
- const cassieCage = new Character();
- [
- {
- name: 'Cassie'
- },
- {
- name: 'Cage'
- },
- {
- header: 'normals'
- },
- {
- Rollin: 'F1'
- }
- ].reduce((accumulator, current, index) => {
- if(index === 0) {
- cassieCage.setFirstName(current.name);
- }
- if(index === 1) {
- cassieCage.setLastName(current.name);
- }
- if(index > 2) {
- let [name] = Object.keys(current);
- cassieCage.addMove(name, current[name]);
- }
- console.log(accumulator)
- return accumulator.concat(current);
- }, []);
- console.log(cassieCage.toString()) // {"name":"Cassie Cage","firstName":"Cassie","lastName":"Cage","moves":[{"name":"Rollin","notatian":"F1"}]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement