Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building blocks #5

Open
hellocan opened this issue Apr 11, 2016 · 5 comments
Open

Building blocks #5

hellocan opened this issue Apr 11, 2016 · 5 comments

Comments

@hellocan
Copy link

Requirements
The constructor should take an array as an argument, this will contain 3 integers of the form [width, length, height] from which the Block should be created.

Examples
let b = new Block([2,4,6]) -> creates a Block object with a width of 2 a length of 4 and a height of 6

b.getWidth() // -> 2

b.getLength() // -> 4

b.getHeight() // -> 6

b.getVolume() // -> 48

b.getSurfaceArea() // -> 88

Your Test Cases:
let block = new Block([2,4,6]);
Test.assertEquals(block.getWidth(), 2)
Test.assertEquals(block.getLength(), 4)
Test.assertEquals(block.getHeight(), 6)
Test.assertEquals(block.getVolume(), 48)
Test.assertEquals(block.getSurfaceArea(), 88)
where By
http://www.codewars.com/kata/55b75fcf67e558d3750000a3/train/javascript

@Go7hic
Copy link
Member

Go7hic commented Apr 11, 2016

class Block{
  constructor(data) {
   this.data = data
  }
  getWidth() {
      return this.data[0]
  }
  getLength() {
    return this.data[1]
  }
  getHeight() {
    return this.data[2]
  }
  getVolume() {
    return this.data[0]*this.data[1]*this.data[2]

  }
  getSurfaceArea() {
    return (this.data[0]*this.data[1] + this.data[0]*this.data[2] + this.data[1]*this.data[2])*2
  }
}

@Go7hic
Copy link
Member

Go7hic commented Apr 11, 2016

提交看了答案这个题目的答案大家都差不多,没有吊打的

@hellocan
Copy link
Author

我的是把每个方法加原型方法上,不懂错在哪了

@Go7hic
Copy link
Member

Go7hic commented Apr 11, 2016

他这个题目是用 es6 的语法 class。话说有空可以熟悉下 es6的语法,我们团队现在都是用 es6了

@hellocan
Copy link
Author

赞!你们团队已经站在互联网前端风口上了!那是不是需要转化es5使用尼--比如 Babel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants