Kumite (ko͞omiˌtā) is the practice of taking techniques learned from Kata and applying them through the act of freestyle sparring.
You can create a new kumite by providing some initial code and optionally some test cases. From there other warriors can spar with you, by enhancing, refactoring and translating your code. There is no limit to how many warriors you can spar with.
A great use for kumite is to begin an idea for a kata as one. You can collaborate with other code warriors until you have it right, then you can convert it to a kata.
Using array methods to solve this issue.
function glutenDetector(ingredients){ const gluten = [ "wheat", "wheat flour", "triticale", "barley", "rye", "brewer's yeast", "malt", "wheatberries", "durum", "emmer", "semolina", "spelt", "farina", "farro", "graham", "kamut", "einkorn" ]; return ingredients .split(/[,()]/) .map((el) => el.trim().toLowerCase()) .some((el) => gluten.includes(el)); }
- function glutenDetector(ingredients){
var gluten = [- const gluten = [
- "wheat",
- "wheat flour",
- "triticale",
- "barley",
- "rye",
- "brewer's yeast",
- "malt",
- "wheatberries",
- "durum",
- "emmer",
- "semolina",
- "spelt",
- "farina",
- "farro",
- "graham",
- "kamut",
- "einkorn"
- ];
var glutenDetect = false;var ingredientsList = ingredients.split(',');ingredientsList.forEach(function(ingredient){var ingredientClean = ingredient.trim().toLowerCase();gluten.forEach(function(glutenIngredient){if(ingredientClean.indexOf(glutenIngredient) !== -1){glutenDetect = true;}});});return glutenDetect;- return ingredients
- .split(/[,()]/)
- .map((el) => el.trim().toLowerCase())
- .some((el) => gluten.includes(el));
- }
Outputs a space-separated list of all integers from 0 to the input byte in descending order. This is a step towards donaldsebleung's goal of 99 Bottles of Beer.
,[[->+>+<<]>>[-<<+>>]<[->>+>+>>-<<----------[[+]>>+<<]>>[[+]<<<----------<+>>>>]<<<[->+>+<<]>>[-<<+>>]<<<<]>[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]>++++++++++++++++++++++++++++++++++++++++++++++++.[-]>[-]<++++++++++++++++++++++++++++++++.[-]<<<-]++++++++++++++++++++++++++++++++++++++++++++++++.
,[->>+>+>>-<<----------[[+]>>+<<]>>[[+]<<<----------<+>>>>]<<<[->+>+<<]>>[-<<+>>]<<<<]>[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]>++++++++++++++++++++++++++++++++++++++++++++++++.- ,[[->+>+<<]>>[-<<+>>]<[->>+>+>>-<<----------[[+]>>+<<]>>[[+]<<<----------<+>>>>]<<<[->+>+<<]>>[-<<+>>]<<<<]>[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]>++++++++++++++++++++++++++++++++++++++++++++++++.[-]>[-]<++++++++++++++++++++++++++++++++.[-]<<<-]++++++++++++++++++++++++++++++++++++++++++++++++.
Test.describe('The Program', function () { Test.it('should correctly convert byte(72) into string starting with "72"', function () { Test.assertEquals(runBF('H'), '72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0'); }); Test.it('should work correctly for a few other examples below byte(100)', function () { Test.assertEquals(runBF('c'), '99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0'); Test.assertEquals(runBF('a'), '97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0'); Test.assertEquals(runBF('F'), '70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0'); Test.assertEquals(runBF('!'), '33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0'); Test.assertEquals(runBF(String.fromCharCode(50)), '50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0'); Test.assertEquals(runBF("\0"), '0'); Test.assertEquals(runBF('0'), '48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0'); Test.assertEquals(runBF('7'), '55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0'); Test.assertEquals(runBF('A'), '65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0'); Test.assertEquals(runBF('\b'), '8 7 6 5 4 3 2 1 0'); }); Test.it('unfortunately doesn\'t work properly above byte(99) :(', function () { console.log('Output for byte(127): ' + runBF(String.fromCharCode(127))); }); });
- Test.describe('The Program', function () {
Test.it('should correctly convert byte(72) into string "72"', function () {Test.assertEquals(runBF('H'), '72');- Test.it('should correctly convert byte(72) into string starting with "72"', function () {
- Test.assertEquals(runBF('H'), '72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0');
- });
- Test.it('should work correctly for a few other examples below byte(100)', function () {
Test.assertEquals(runBF('c'), '99');Test.assertEquals(runBF('a'), '97');Test.assertEquals(runBF('F'), '70');Test.assertEquals(runBF('!'), '33');Test.assertEquals(runBF(String.fromCharCode(50)), '50');- Test.assertEquals(runBF('c'), '99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0');
- Test.assertEquals(runBF('a'), '97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0');
- Test.assertEquals(runBF('F'), '70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0');
- Test.assertEquals(runBF('!'), '33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0');
- Test.assertEquals(runBF(String.fromCharCode(50)), '50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0');
- Test.assertEquals(runBF("\0"), '0');
Test.assertEquals(runBF('0'), '48');Test.assertEquals(runBF('7'), '55');Test.assertEquals(runBF('A'), '65');- Test.assertEquals(runBF('0'), '48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0');
- Test.assertEquals(runBF('7'), '55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0');
- Test.assertEquals(runBF('A'), '65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0');
- Test.assertEquals(runBF('\b'), '8 7 6 5 4 3 2 1 0');
- });
- Test.it('unfortunately doesn\'t work properly above byte(99) :(', function () {
- console.log('Output for byte(127): ' + runBF(String.fromCharCode(127)));
- });
- });
/* Array.reduce( * (accumulator, currentValue, currentIndex, array) => { * return accumulator + currentValue; * }, * initialValue * ); */ function sumOfElements(arr) { if(arr==undefined) return 0; return arr.reduce((sum, currentValue) => sum + currentValue,0); }
- /* Array.reduce(
- * (accumulator, currentValue, currentIndex, array) => {
- * return accumulator + currentValue;
- * },
- * initialValue
- * );
- */
function sumOfElements(arr) {return arr ? arr.reduce( (sum, currentValue) => sum + currentValue) : 0;- function sumOfElements(arr) {
- if(arr==undefined) return 0;
- return arr.reduce((sum, currentValue) => sum + currentValue,0);
- }
This kumite is not working as intended so just testing something.
No need to declare number outside of for loop.
public class CountTheDigit { public static int nbDig(int n, int d) { int count=0; for(int i=0; i<n; i++) { String number=(i*i)+""; count += number.length() - number.replace(d+"", "").length(); } return count; } }
- public class CountTheDigit {
- public static int nbDig(int n, int d) {
String number = "";- int count=0;
- for(int i=0; i<n; i++) {
number=(i*i)+"";- String number=(i*i)+"";
- count += number.length() - number.replace(d+"", "").length();
- }
- return count;
- }
- }
refactorting
function nextGeneration(grid) { // pregenerated coords const neighboursCords = [[0, 1], [0, -1], [1, 1], [1, 0], [1, -1], [-1, 1], [-1, 0], [-1, -1]]; const neighboursCollector = (rowIndex, columnIndex) => ([x, y]) => grid[rowIndex + x][columnIndex + y]; const sum = (a, b) => a + b; return grid.map((row, rowIndex) => row.map((column, columnIndex) => { const isValid = rowIndex !== 0 && columnIndex !== 0 && rowIndex < grid.length - 1 && columnIndex < row.length - 1; if (!isValid) return 0; const currentCellValuesCollector = neighboursCollector(rowIndex, columnIndex); const neighboursCount = neighboursCords .map(currentCellValuesCollector) .reduce(sum); return +(neighboursCount === 3 || (column === 1 && neighboursCount === 2)); }) ); }
- function nextGeneration(grid) {
var neighboursCords = [[0, 1], [0, -1], [1, 1], [1, 0], [1, -1], [-1, 1], [-1, 0], [-1, -1]];return grid.map((r, ri) =>r.map((c, ci) => {if (ri !== 0 && ci !== 0 && ri < grid.length - 1 && ci < r.length - 1) {let neighboursCount = neighboursCords.reduce((s, v) => s += grid[ri + v[0]][ci + v[1]], 0);return 0 + (neighboursCount === 3 || (c === 1 && neighboursCount === 2));}return 0;}));- // pregenerated coords
- const neighboursCords = [[0, 1], [0, -1], [1, 1], [1, 0], [1, -1], [-1, 1], [-1, 0], [-1, -1]];
- const neighboursCollector = (rowIndex, columnIndex) => ([x, y]) => grid[rowIndex + x][columnIndex + y];
- const sum = (a, b) => a + b;
- return grid.map((row, rowIndex) =>
- row.map((column, columnIndex) => {
- const isValid = rowIndex !== 0 && columnIndex !== 0 &&
- rowIndex < grid.length - 1 && columnIndex < row.length - 1;
- if (!isValid) return 0;
- const currentCellValuesCollector = neighboursCollector(rowIndex, columnIndex);
- const neighboursCount = neighboursCords
- .map(currentCellValuesCollector)
- .reduce(sum);
- return +(neighboursCount === 3 || (column === 1 && neighboursCount === 2));
- })
- );
- }
function wordCount(str) { return str.replace(/\s/g, '').length ? str.trim().split(/\s+/).length : 0; }
- function wordCount(str) {
return str.length > 2 ? str.split(' ').length : 1;- return str.replace(/\s/g, '').length ? str.trim().split(/\s+/).length : 0;
- }
// TODO: Replace examples and use TDD development by writing your own tests // These are some CW specific test methods available: // Test.expect(boolean, [optional] message) // Test.assertEquals(actual, expected, [optional] message) // Test.assertSimilar(actual, expected, [optional] message) // Test.assertNotEquals(actual, expected, [optional] message) // NodeJS assert is also automatically required for you. // assert(true) // assert.strictEqual({a: 1}, {a: 1}) // assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]}) // You can also use Chai (http://chaijs.com/) by requiring it yourself // var expect = require("chai").expect; // var assert = require("chai").assert; // require("chai").should(); Test.assertEquals(wordCount(""), 0); Test.assertEquals(wordCount(" "), 0); Test.assertEquals(wordCount(" "), 0); Test.assertEquals(wordCount(" "), 0); Test.assertEquals(wordCount(" v"), 1); Test.assertEquals(wordCount("Word"), 1); Test.assertEquals(wordCount("Wo r d"), 3); Test.assertEquals(wordCount("Bob the t-rex"), 3);
- // TODO: Replace examples and use TDD development by writing your own tests
- // These are some CW specific test methods available:
- // Test.expect(boolean, [optional] message)
- // Test.assertEquals(actual, expected, [optional] message)
- // Test.assertSimilar(actual, expected, [optional] message)
- // Test.assertNotEquals(actual, expected, [optional] message)
- // NodeJS assert is also automatically required for you.
- // assert(true)
- // assert.strictEqual({a: 1}, {a: 1})
- // assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]})
- // You can also use Chai (http://chaijs.com/) by requiring it yourself
- // var expect = require("chai").expect;
- // var assert = require("chai").assert;
- // require("chai").should();
- Test.assertEquals(wordCount(""), 0);
- Test.assertEquals(wordCount(" "), 0);
- Test.assertEquals(wordCount(" "), 0);
- Test.assertEquals(wordCount(" "), 0);
- Test.assertEquals(wordCount(" v"), 1);
- Test.assertEquals(wordCount("Word"), 1);
- Test.assertEquals(wordCount("Wo r d"), 3);
- Test.assertEquals(wordCount("Bob the t-rex"), 3);
I've made changes that sum method ignores everything but numbers
Also I've refactored code to ES6
const sum = arr => { const reducer = (sum, elem) => typeof elem === 'number' ? (sum + elem) : sum return arr.reduce(reducer, 0); }
function sum(arr) {return arr.reduce((sum, elem) => sum + elem, 0);}- const sum = arr => {
- const reducer = (sum, elem) => typeof elem === 'number' ? (sum + elem) : sum
- return arr.reduce(reducer, 0);
- }
describe("Sum", function(){ it("should sum correctly", function(){ Test.assertEquals(sum([5,2,1]), 8, "Sum equals to 8"); }); it("should sum only numbers and skip the rest", function(){ Test.assertEquals(sum([5, 'a', 2, '$', 1]), 8, "Sum equals to 8"); Test.assertEquals(sum([5, '3', 2, '$', 1]), 8, "Sum equals to 8"); Test.assertEquals(sum([5, '3', 2, Infinity, 1]), Infinity, "Sum equals to Infinity"); }); });
- describe("Sum", function(){
- it("should sum correctly", function(){
Test.assertEquals(sum([5,2,1]), 8, "Sum equal to 8");- Test.assertEquals(sum([5,2,1]), 8, "Sum equals to 8");
- });
- it("should sum only numbers and skip the rest", function(){
- Test.assertEquals(sum([5, 'a', 2, '$', 1]), 8, "Sum equals to 8");
- Test.assertEquals(sum([5, '3', 2, '$', 1]), 8, "Sum equals to 8");
- Test.assertEquals(sum([5, '3', 2, Infinity, 1]), Infinity, "Sum equals to Infinity");
- });
- });