v1
- by nikkypizza 11/11/202200
Setup HTML - click to add setup HTML
disable setup JavaScript
Setup JavaScript
const input = [
  { value: 'ss  i', order: 2, expired: true },
  { value: 'evol', order: 3, expired: true },
  { value: 'ff kciuq', order: 1, expired: false },
  { value: 'te j j ', order: 5, expired: false },
  { value: 'xooff', order: 4, expired: false },
];

const solution1 = (arr) => arr
.filter(it => !it.expired)
.sort((a, b) => a.order - b.order)
.reduce((acc, it) => {
  acc += it.value.split('').reverse().join('');
  acc = Array.from(new Set(acc)).join('')
  return acc;
},'');

const solution2 = (arr) => {
  let result = '';

  const sortedArr = arr.slice().sort((a, b) => a.order - b.order);

  sortedArr.forEach(it => {
    if (!it.expired) {
      result += it.value.split('').reverse().join('');
    }
  });

  return [...new Set(result)].join('');
}

const solution3 = (arr) => {
  return arr
    .filter(({ expired }) => !expired)
    .sort((a, b) => a.order - b.order)
    .reduce((acc, res) => {
        acc.push(...res.value.split('').reverse());
        return Array.from(new Set(acc));
      }, [])
    .join('');
};

const solution4 = (arr) => {
  const result = arr
  .filter((it) => !it.expired)
  .sort((a, b) => a.order - b.order)
  .reduce((acc, res) => {
    acc.push(...res.value.split('').reverse());
    return acc;
  }, []);
  return Array.from(new Set(result)).join('');
}
delete caserun single casemove downdrag and drop case


ready



solution1(input)
delete caserun single casemove upmove downdrag and drop case


ready



solution2(input)
delete caserun single casemove upmove downdrag and drop case


ready



solution3(input)
delete caserun single casemove updrag and drop case


ready



solution4(input)
Test Case - click to add another test case
Teardown JS - click to add teardown JavaScript
Output (DOM) - click to monitor output (DOM) while test is running
RUN