From bf1e97e556e6114d13851ff880abfe7c6f5cd251 Mon Sep 17 00:00:00 2001 From: atom-box Date: Fri, 3 Dec 2021 16:55:43 -0600 Subject: [PATCH] Works. Remember that i is the index, not the value itself. --- rightDigit.js | 9 ++++++--- test/rightDigit.js | 23 ++++++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/rightDigit.js b/rightDigit.js index a913f48..c23781a 100644 --- a/rightDigit.js +++ b/rightDigit.js @@ -1,6 +1,9 @@ exports.rightDigit = function(numbers){ - console.log('Been to Spain!'); - var tuna = 42; - return [111, 222]; + arrayAnswer = []; + for (i in numbers){ + var digit = numbers[i] % 10; + arrayAnswer.push(digit); + } + return arrayAnswer; } diff --git a/test/rightDigit.js b/test/rightDigit.js index 3c70d6a..7ddf7b3 100644 --- a/test/rightDigit.js +++ b/test/rightDigit.js @@ -1,18 +1,31 @@ // Given a list of non-negative integers, return an integer list of the rightmost digits. (Note: use %) // https://codingbat.com/prob/p152194 // https://semaphoreci.com/community/tutorials/getting-started-with-node-js-and-mocha -console.log('Been to Germany!'); var expect = require("chai").expect; var thingtotest = require("../rightDigit.js"); -console.log('111' + typeof thingtotest.rightDigit); -console.log('222' + Object.keys(thingtotest.rightDigit).toString()); -console.log('333' + Object.keys(thingtotest.rightDigit).length); + describe('Digit getter', () => { it('gets just the last digit of each', () =>{ var blueHex = thingtotest.rightDigit([1, 22, 93]); - expect(blueHex).to.equal([]); + expect(blueHex).to.deep.equal([1, 2, 3]); + }) +}); + +describe('Digit getter', () => { + it('gets just the last digit of each', () =>{ + + var blueHex = thingtotest.rightDigit([16, 8, 886, 8, 1]); + expect(blueHex).to.deep.equal([6, 8, 6, 8, 1]); + }) +}); + +describe('Digit getter', () => { + it('gets just the last digit of each', () =>{ + + var blueHex = thingtotest.rightDigit([10, 0]); + expect(blueHex).to.deep.equal([0, 0]); }) });