Почему toSlug2 функция, а toSlug1 нет?
//associative
add(add(x, y), z) == add(x, add(y, z));
//commutative
add(x, y) == add(y, x);
//identity
add(x, 0) == x;
//distributive
add(multiply(x, y), multiply(x, z)) == multiply(x, add(y, z));
//Deterministic
//No observable Side-Effects
//Reliable
//Portable
//Reusable
//Testable
//Composable
//Properties/Contract
//not a function
const toSlug1 = (title) => {
const urlFriendly = title.replace('/W+/ig', '-');
if (urlFriendly.length < 1) {
throw new Error('is bad');
}
return urlFriendly;
};
//function
const toSlug2 = (title) => {
return new Promise((res, rej) => {
const urlFriendly = title.replace('/W+/ig', '-');
if (urlFriendly.length < 1) {
rej(new Error('is bad'));
}
return res(urlFriendly);
});
};