These are my answers that I came up with for The Odin's Project exercises using arrow functions.
1. Write a function called add7 that takes one number and returns that number + 7.
const add7 = (num) => num + 7;
2. Write a function called multiply that takes 2 numbers and returns their product.
const multiply = (x, y) => x * y;
3. Write a function called capitalize that takes a string and returns that string with only the first letter capitalized. Make sure that it can take strings that are lowercase, UPPERCASE or BoTh.
const capitalize = (str) => {
let firstLetter = str.slice(0,1);
let restOfStr = str.slice(1,);
return `${firstLetter.toUpperCase()}${restOfStr}`;
}
4. Write a function called lastLetter that takes a string and returns the very last letter of that string.
Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.
Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.
Top comments (2)
ES6 arrow functions give you an alternative way to write shorter syntax compared to function expression.
Because of this:
Agree. This is a good solution as well.