Task: “Expand words in a sentence”
Write a reverseWords (str) function that accepts a string as input. The function should return a new line, putting the words in reverse order. If the line has punctuation marks, you can delete or leave them - at your discretion.
function reverseWords(str) {
return str.split(" ").reverse().join(" ")
}
// TODO: Add your tests here
// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
// are still available for now.
//
// For new tests, using [Chai](https://chaijs.com/) is recommended.
// You can use it by requiring:
// const assert = require("chai").assert;
// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});
Task 2: "FizzBuzz"
Write a function fizzBuzz (n) that takes an integer as argument.
The function should output numbers from 1 to n to the console, replacing the numbers:
• multiples of three - on fizz;
• multiples of five - on buzz;
• multiples of three and five at the same time - on fizzbuzz.
function fizzBuzz(num) {
for (let i=1;i <= (num); i++) {
let fb = '';
if (i%3===0) {fb = fb + 'fizz'};
if (i%5===0) {fb = fb + 'buzz'};
if (fb==='') { console.log(i); } else { console.log(fb); };
}
};
fizzBuzz(15); //
// TODO: Add your tests here
// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
// are still available for now.
//
// For new tests, using [Chai](https://chaijs.com/) is recommended.
// You can use it by requiring:
// const assert = require("chai").assert;
// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});