-
Notifications
You must be signed in to change notification settings - Fork 24
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
solution and test for problem #14 #93
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Rahul Kalra | ||
// Return an array of the diagnal values starting from 0,0 from a 2D array input(gauranteed to be square). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rkalra247, please make sure there is no typo in comment, and add comments like this: https://github.com/llipio/algorithms/pull/55/files |
||
|
||
const solution = (array) =>{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't use |
||
let newArray = []; | ||
|
||
for(let i = 0; i < array.length; i++){ | ||
for(let j = 0; j < array.length; j++){ | ||
if(i === j){ | ||
newArray.push(array[i][j]); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation |
||
} | ||
} | ||
return newArray; | ||
}; | ||
|
||
module.exports = {solution}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
let expect = require('chai').expect; | ||
let solution = require('../solutions/14').solution; | ||
|
||
describe('Diagonal Array', () => { | ||
it('should return an array of diagonal values', () => { | ||
expect(solution([[1,2,3],[2,3,4],[3,4,5]])).to.eql([1,3,5]); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please write proper comments, like here: https://github.com/llipio/algorithms/pull/75/files