Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebacruz committed May 2, 2022
2 parents 9e65211 + b63e099 commit abd6ad4
Show file tree
Hide file tree
Showing 4 changed files with 14,845 additions and 2,662 deletions.
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
* @param {String} [and=' and '] Text to put between the next-to-last element and the last element
* @return {String} The constructed string
*/
module.exports = function (items = [], separator = ', ', and = ' and ') {
const arr = [].concat(items);
const last = arr.pop();
const andlist = (items = [], separator = ', ', and = ' and ') => {
const itemsCopy = [...items];
const last = itemsCopy.pop();

if (arr.length === 0) {
if (itemsCopy.length === 0) {
return last;
}

return [arr.join(separator), last].join(and);
return [itemsCopy.join(separator), last].join(and);
};

export default andlist;
Loading

0 comments on commit abd6ad4

Please sign in to comment.