Ad
Arrays
Data Types
Map/Reduce
Algorithms
Logic
Code
Diff
  • const duplicates = a => a.reduce((r, v, i, l) => !r.includes(v) && l.indexOf(v) !== i ? [...r, v] : r, []);
    • function duplicates(arr) {
    • var out = [];
    • for(var x=0;x<arr.length-1;x++)
    • {
    • var ch = arr[x];
    • for(var y=x+1;y<arr.length;y++)
    • {
    • var comp = arr[y];
    • if (comp === ch && out.indexOf(comp) === -1)
    • {
    • out.push(comp);
    • break;
    • }
    • }
    • }
    • out.sort();
    • return out;
    • }
    • const duplicates = a => a.reduce((r, v, i, l) => !r.includes(v) && l.indexOf(v) !== i ? [...r, v] : r, []);
Code
Diff
  • const middleCharacter = s => s.slice(s.length/2 - !(s.length % 2), s.length/2+1);
    • var middleCharacter = (str) => str.slice(str.length/2 - !(str.length % 2), str.length/2+1);
    • const middleCharacter = s => s.slice(s.length/2 - !(s.length % 2), s.length/2+1);
Code
Diff
  • const convert = n => Number(n.toFixed(2));
    • const convert = (num) => {
    • return parseFloat(num.toFixed(2));
    • };
    • const convert = n => Number(n.toFixed(2));