what have done..
-
Correct test case
-
Return count even if the sentence does not include any of letters (which is count zero)
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)
- }
describe("Should return how many of a certain letter is in a sentence", function(){ it("should test for the amount of letters in the given letters", function(){ Test.assertSimilar( testAmount("a long sentence of random things about the sentences",["a","o"]), [3, 4] ); Test.assertSimilar( testAmount("a long sentence of random things about the sentences",["a","k"]), [3, 0] ); }); });
- describe("Should return how many of a certain letter is in a sentence", function(){
- it("should test for the amount of letters in the given letters", function(){
Test.assertEquals(testAmount("a long sentence of random things about the sentences",["a","o"]), [3, 4]);- Test.assertSimilar(
- testAmount("a long sentence of random things about the sentences",["a","o"]), [3, 4]
- );
- Test.assertSimilar(
- testAmount("a long sentence of random things about the sentences",["a","k"]), [3, 0]
- );
- });
- });
Mathematics
Algorithms
Logic
Numbers
Fundamentals
Arrays
Data Types
Map/Reduce
Algorithms
Logic
- result in ordered by value
- correct test cases
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, [])
Test.assertEquals(duplicates([1, 2, 4, 4, 3, 3, 1, 5, 3]).toString(), [1,3,4].toString(), "Sorry, your array does not have the correct contents"); Test.assertEquals(duplicates([0, 1, 2, 3, 4, 5]).toString(), [].toString(), "Sorry, your array does not have the correct contents"); Test.assertEquals(duplicates([0, 1, '1', 2, 3, '4', 4, 5, 5]).toString(), [5].toString(), "Sorry, your array does not have the correct contents"); Test.assertEquals(duplicates([0, '', null, undefined, false]).toString(), [].toString(), "Sorry, your array does not have the correct contents"); Test.assertEquals(duplicates.toString().indexOf("for"), -1, "You can't use for loops"); Test.assertEquals(duplicates.toString().indexOf("forEach"), -1, "You can't use for loops"); Test.assertNotEquals(duplicates.toString().indexOf("reduce"), -1, "You should be using reduce in your solution");
Test.assertEquals(duplicates([1, 2, 4, 4, 3, 3, 1, 5, 3]).toString, [1,3,4].toString, "Sorry, your array does not have the correct contents");Test.assertEquals(duplicates([0, 1, 2, 3, 4, 5]).toString, [].toString, "Sorry, your array does not have the correct contents");- Test.assertEquals(duplicates([1, 2, 4, 4, 3, 3, 1, 5, 3]).toString(), [1,3,4].toString(), "Sorry, your array does not have the correct contents");
- Test.assertEquals(duplicates([0, 1, 2, 3, 4, 5]).toString(), [].toString(), "Sorry, your array does not have the correct contents");
- Test.assertEquals(duplicates([0, 1, '1', 2, 3, '4', 4, 5, 5]).toString(), [5].toString(), "Sorry, your array does not have the correct contents");
- Test.assertEquals(duplicates([0, '', null, undefined, false]).toString(), [].toString(), "Sorry, your array does not have the correct contents");
- Test.assertEquals(duplicates.toString().indexOf("for"), -1, "You can't use for loops");
- Test.assertEquals(duplicates.toString().indexOf("forEach"), -1, "You can't use for loops");
- Test.assertNotEquals(duplicates.toString().indexOf("reduce"), -1, "You should be using reduce in your solution");