Ad

what have done..

  • Correct test case

  • Return count even if the sentence does not include any of letters (which is count zero)

Code
Diff
  • function testAmount(sentence, letters){
      return letters.map(letter =>
        [...sentence].filter(test => letter === test).length)
    }
    • function testAmount(sentence, letters) {
    • return letters.map(letter => sentence.match(RegExp(letter, 'g')).length);
    • function testAmount(sentence, letters){
    • return letters.map(letter =>
    • [...sentence].filter(test => letter === test).length)
    • }
Mathematics
Algorithms
Logic
Numbers
Fundamentals
Code
Diff
  • const dice = _ => -~(Math.random()*6);
    • const dice=_=>~~(Math.random()*6)+1;
    • const dice = _ => -~(Math.random()*6);
Arrays
Data Types
Map/Reduce
Algorithms
Logic
  • result in ordered by value
  • correct test cases
Code
Diff
  • const duplicates = n => n.sort((a, b) => a - b)
      .reduce((p, c, i, a) => c !== [...p].pop() && c === a[i-1] ? [...p, c] : p, [])
    • 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 = n => n.sort((a, b) => a - b)
    • .reduce((p, c, i, a) => c !== [...p].pop() && c === a[i-1] ? [...p, c] : p, [])
Code
Diff
  • const middleCharacter = s => s.slice(~(s.length/2), -~(s.length/2));
    • const middleCharacter = s => s.slice(s.length/2 - !(s.length % 2), s.length/2+1);
    • const middleCharacter = s => s.slice(~(s.length/2), -~(s.length/2));