From 3ba220929240ae1bcaeb75d6d1f87599a570e5f2 Mon Sep 17 00:00:00 2001 From: Rahul Kalra Date: Thu, 8 Jun 2017 10:04:02 -0700 Subject: [PATCH] solution and test for problem #14 --- solutions/14.js | 17 +++++++++++++++++ test/14.js | 8 ++++++++ 2 files changed, 25 insertions(+) create mode 100644 solutions/14.js create mode 100644 test/14.js diff --git a/solutions/14.js b/solutions/14.js new file mode 100644 index 0000000..7627775 --- /dev/null +++ b/solutions/14.js @@ -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). + +const solution = (array) =>{ + 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]); + } + } + } + return newArray; +}; + +module.exports = {solution}; diff --git a/test/14.js b/test/14.js new file mode 100644 index 0000000..792aad1 --- /dev/null +++ b/test/14.js @@ -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]); + }); + });