Skip to content

Instantly share code, notes, and snippets.

@joefearnley
Last active June 28, 2020 14:05
Show Gist options
  • Save joefearnley/adef67165c0beea72b477f0ed6c5caa3 to your computer and use it in GitHub Desktop.
Save joefearnley/adef67165c0beea72b477f0ed6c5caa3 to your computer and use it in GitHub Desktop.
10 day JS challenge - Day: 4: Array Replace
const arrayReplace = (array, elemToReplace, substitutionElem) => array.map((el, i) => el === elemToReplace ? substitutionElem : el);
describe('arrayReplace()', () => {
it('adds a border around entire application', () => {
// arrange
const array = [1, 2, 1];
const elemToReplace = 1;
const substitutionElem = 3;
// act
const result = arrayReplace(array, elemToReplace, substitutionElem);
// log
console.log("result: ", result);
// assert
expect(result).toEqual([3, 2, 3]);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment