Advertisement
kstoyanov

07. Unique Sequences v2

Sep 23rd, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function uniqueSequences(input) {
  2.   const storedArrs = new Set();
  3.  
  4.   input.forEach((arr) => {
  5.     const sortArr = JSON.parse(arr).sort((a, b) => b - a);
  6.     storedArrs.add(JSON.stringify(sortArr));
  7.   });
  8.  
  9.   const resArr = [];
  10.   [...storedArrs].forEach((el) => resArr.push(JSON.parse(el)));
  11.  
  12.   resArr.sort((a, b) => a.length - b.length);
  13.  
  14.   resArr.forEach((a) => console.log(`[${a.join(', ')}]`));
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement