Arrays
Write a function, onlyOdds that accepts an array of numbers as an argument. It should return a new array that contains only the odd numbers from the given array.
You may assume any array given as an argument will not be empty.
let onlyOdds = input => {
let newArray = []
for (let i = 0; i < input.length; i++) {
let currentElem = input[i]
if (currentElem % 2 === 1) {
newArray.push(currentElem)
}
}
return newArray
}
const chai = require("chai");
const assert = chai.assert;
var expect = require('chai').expect
describe('onlyOdds', () => {
it('is a function', () => {
expect(typeof onlyOdds).to.equal('function');
});
it('returns an array', () => {
let returnedValue = onlyOdds([1, 2, 3]);
expect(Array.isArray(returnedValue)).to.equal(true);
});
it('returns an array with only the odd numbers from the given array', () => {
let returnedValue = onlyOdds([5, 10, 15, 20]);
expect(returnedValue).to.eql([5, 15]);
});
});