js version with fixed TestCases.
function multiplicationTable(){ let arr = []; for(let i=1; i<6; i++){ arr.push([]); for(let j=1; j<13; j++){ arr[arr.length-1].push(`${i} * ${j} = ${i*j}`); } } return arr.map(e => e.join('\n')).join('\n\n'); }
#include<stdio.h>int main(){int i=1;while(i<=5){int j=1;while(j<=12){printf("%d * %d =%d \n", i,j, i*j);j++;- function multiplicationTable(){
- let arr = [];
- for(let i=1; i<6; i++){
- arr.push([]);
- for(let j=1; j<13; j++){
- arr[arr.length-1].push(`${i} * ${j} = ${i*j}`);
- }
i++;printf("\n");}return(0);- } return arr.map(e => e.join('\n')).join('\n\n');
- }
// Since Node 10, we're using Mocha. // You can use `chai` for assertions. const chai = require("chai"); const assert = chai.assert; // Uncomment the following line to disable truncating failure messages for deep equals, do: // chai.config.truncateThreshold = 0; // Since Node 12, we no longer include assertions from our deprecated custom test framework by default. // Uncomment the following to use the old assertions: // const Test = require("@codewars/test-compat"); function multiplicationTable(){ let arr = []; for(let i=1; i<6; i++){ arr.push([]); for(let j=1; j<13; j++){ arr[arr.length-1].push(`${i} * ${j} = ${i*j}`); } } return arr.map(e => e.join('\n')).join('\n\n'); } describe("Solution", function() { it("should give multiplication table from 1 to 5", function() { assert.strictEqual(multiplicationTable(), `1 * 1 = 1 1 * 2 = 2 1 * 3 = 3 1 * 4 = 4 1 * 5 = 5 1 * 6 = 6 1 * 7 = 7 1 * 8 = 8 1 * 9 = 9 1 * 10 = 10 1 * 11 = 11 1 * 12 = 12 2 * 1 = 2 2 * 2 = 4 2 * 3 = 6 2 * 4 = 8 2 * 5 = 10 2 * 6 = 12 2 * 7 = 14 2 * 8 = 16 2 * 9 = 18 2 * 10 = 20 2 * 11 = 22 2 * 12 = 24 3 * 1 = 3 3 * 2 = 6 3 * 3 = 9 3 * 4 = 12 3 * 5 = 15 3 * 6 = 18 3 * 7 = 21 3 * 8 = 24 3 * 9 = 27 3 * 10 = 30 3 * 11 = 33 3 * 12 = 36 4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16 4 * 5 = 20 4 * 6 = 24 4 * 7 = 28 4 * 8 = 32 4 * 9 = 36 4 * 10 = 40 4 * 11 = 44 4 * 12 = 48 5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45 5 * 10 = 50 5 * 11 = 55 5 * 12 = 60`); }); });
- // Since Node 10, we're using Mocha.
- // You can use `chai` for assertions.
- const chai = require("chai");
- const assert = chai.assert;
- // Uncomment the following line to disable truncating failure messages for deep equals, do:
- // chai.config.truncateThreshold = 0;
- // Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
- // Uncomment the following to use the old assertions:
- // const Test = require("@codewars/test-compat");
- function multiplicationTable(){
- let arr = [];
- for(let i=1; i<6; i++){
- arr.push([]);
- for(let j=1; j<13; j++){
- arr[arr.length-1].push(`${i} * ${j} = ${i*j}`);
- }
- } return arr.map(e => e.join('\n')).join('\n\n');
- }
- describe("Solution", function() {
- it("should give multiplication table from 1 to 5", function() {
- assert.strictEqual(multiplicationTable(),
- `1 * 1 = 1
- 1 * 2 = 2
- 1 * 3 = 3
- 1 * 4 = 4
- 1 * 5 = 5
- 1 * 6 = 6
- 1 * 7 = 7
- 1 * 8 = 8
- 1 * 9 = 9
- 1 * 10 = 10
- 1 * 11 = 11
- 1 * 12 = 12
- 2 * 1 = 2
- 2 * 2 = 4
- 2 * 3 = 6
- 2 * 4 = 8
- 2 * 5 = 10
- 2 * 6 = 12
- 2 * 7 = 14
- 2 * 8 = 16
- 2 * 9 = 18
- 2 * 10 = 20
- 2 * 11 = 22
- 2 * 12 = 24
- 3 * 1 = 3
- 3 * 2 = 6
- 3 * 3 = 9
- 3 * 4 = 12
- 3 * 5 = 15
- 3 * 6 = 18
- 3 * 7 = 21
- 3 * 8 = 24
- 3 * 9 = 27
- 3 * 10 = 30
- 3 * 11 = 33
- 3 * 12 = 36
- 4 * 1 = 4
- 4 * 2 = 8
- 4 * 3 = 12
- 4 * 4 = 16
- 4 * 5 = 20
- 4 * 6 = 24
- 4 * 7 = 28
- 4 * 8 = 32
- 4 * 9 = 36
- 4 * 10 = 40
- 4 * 11 = 44
- 4 * 12 = 48
- 5 * 1 = 5
- 5 * 2 = 10
- 5 * 3 = 15
- 5 * 4 = 20
- 5 * 5 = 25
- 5 * 6 = 30
- 5 * 7 = 35
- 5 * 8 = 40
- 5 * 9 = 45
- 5 * 10 = 50
- 5 * 11 = 55
- 5 * 12 = 60`);
- });
- });
~ Fixed TestCases ~
function findSenior(list) { const maxAge = Math.max(...list.map(e => e.age)); return list.filter(e => e.age===maxAge); }
// Solution- function findSenior(list) {
let maxAge = 0;list.forEach((dev) => { // ho usato forEach per trovare l'età massima tra gli sviluppatoriif (dev.age > maxAge) {maxAge = dev.age;}});return list.filter((dev) => dev.age === maxAge); // ho usato filter per filtrare gli sviluppatori con l'età massima- const maxAge = Math.max(...list.map(e => e.age));
- return list.filter(e => e.age===maxAge);
- }
// Since Node 10, we're using Mocha. // You can use `chai` for assertions. const chai = require("chai"); const assert = chai.assert; // Uncomment the following line to disable truncating failure messages for deep equals, do: // chai.config.truncateThreshold = 0; // Since Node 12, we no longer include assertions from our deprecated custom test framework by default. // Uncomment the following to use the old assertions: // const Test = require("@codewars/test-compat"); function findSenior(list) { const maxAge = Math.max(...list.map(e => e.age)); return list.filter(e => e.age===maxAge); } const list1 = [ { firstName: "Gabriel", lastName: "X.", country: "Monaco", continent: "Europe", age: 49, language: "PHP", }, { firstName: "Odval", lastName: "Fabio.", country: "Mongolia", continent: "Asia", age: 38, language: "Python", }, { firstName: "Guea", lastName: "Serge.", country: "Italy", continent: "Europe", age: 24, language: "Java", }, { firstName: "Sou", lastName: "Bocc.", country: "Japan", continent: "Asia", age: 49, language: "PHP", }, ]; const list2 = [ { firstName: "Gabriel", lastName: "X.", country: "Monaco", continent: "Europe", age: 49, language: "PHP", }, { firstName: "Odval", lastName: "F.", country: "Mongolia", continent: "Asia", age: 38, language: "Python", }, { firstName: "Emilija", lastName: "S.", country: "Lithuania", continent: "Europe", age: 19, language: "Python", }, { firstName: "Sou", lastName: "B.", country: "Japan", continent: "Asia", age: 49, language: "PHP", }, { firstName: "Sou", lastName: "B.", country: "Japan", continent: "Asia", age: 49, language: "PHP", }, ]; describe("Solution", function() { it("should filter the most senior developer", function() { assert.strictEqual(JSON.stringify(findSenior(list1)), JSON.stringify([{ firstName: "Gabriel", lastName: "X.", country: "Monaco", continent: "Europe", age: 49, language: "PHP"},{ firstName: "Sou", lastName: "Bocc.", country: "Japan", continent: "Asia", age: 49, language: "PHP"}])); assert.strictEqual(JSON.stringify(findSenior(list2)),JSON.stringify([{ firstName: 'Gabriel', lastName: 'X.', country: 'Monaco', continent: 'Europe', age: 49, language:'PHP' }, { firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 49, language: 'PHP' }, { firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 49, language: 'PHP' }])); })});
- // Since Node 10, we're using Mocha.
- // You can use `chai` for assertions.
- const chai = require("chai");
- const assert = chai.assert;
- // Uncomment the following line to disable truncating failure messages for deep equals, do:
- // chai.config.truncateThreshold = 0;
- // Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
- // Uncomment the following to use the old assertions:
- // const Test = require("@codewars/test-compat");
- function findSenior(list) {
- const maxAge = Math.max(...list.map(e => e.age));
- return list.filter(e => e.age===maxAge);
- }
- const list1 = [
- {
- firstName: "Gabriel",
- lastName: "X.",
- country: "Monaco",
- continent: "Europe",
- age: 49,
- language: "PHP",
- },
- {
- firstName: "Odval",
- lastName: "Fabio.",
- country: "Mongolia",
- continent: "Asia",
- age: 38,
- language: "Python",
- },
- {
- firstName: "Guea",
- lastName: "Serge.",
- country: "Italy",
- continent: "Europe",
- age: 24,
- language: "Java",
- },
- {
- firstName: "Sou",
- lastName: "Bocc.",
- country: "Japan",
- continent: "Asia",
- age: 49,
- language: "PHP",
- },
- ];
- const list2 = [
- {
- firstName: "Gabriel",
- lastName: "X.",
- country: "Monaco",
- continent: "Europe",
- age: 49,
- language: "PHP",
- },
- {
- firstName: "Odval",
- lastName: "F.",
- country: "Mongolia",
- continent: "Asia",
- age: 38,
- language: "Python",
- },
- {
- firstName: "Emilija",
- lastName: "S.",
- country: "Lithuania",
- continent: "Europe",
- age: 19,
- language: "Python",
- },
- {
- firstName: "Sou",
- lastName: "B.",
- country: "Japan",
- continent: "Asia",
- age: 49,
- language: "PHP",
- },
- {
- firstName: "Sou",
- lastName: "B.",
- country: "Japan",
- continent: "Asia",
- age: 49,
- language: "PHP",
- },
- ];
console.log(findSenior(list1)); // [{ firstName: 'Gabriel', lastName: 'X.', country: 'Monaco', continent: 'Europe', age: 49, language:'PHP' }, { firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 49, language: 'PHP' }]console.log(findSenior(list2)); // [{ firstName: 'Gabriel', lastName: 'X.', country: 'Monaco', continent: 'Europe', age: 49, language:'PHP' }, { firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 49, language: 'PHP' },// { firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 49, language: 'PHP' }]function findSenior(list) {let maxAge = 0;list.forEach((dev) => { // ho usato forEach per trovare l'età massima tra gli sviluppatoriif (dev.age > maxAge) {maxAge = dev.age;}});return list.filter((dev) => dev.age === maxAge); // ho usato filter per filtrare gli sviluppatori con l'età massima}- describe("Solution", function() {
- it("should filter the most senior developer", function() {
- assert.strictEqual(JSON.stringify(findSenior(list1)), JSON.stringify([{ firstName: "Gabriel", lastName: "X.", country: "Monaco", continent: "Europe", age: 49, language: "PHP"},{ firstName: "Sou", lastName: "Bocc.", country: "Japan", continent: "Asia", age: 49, language: "PHP"}]));
- assert.strictEqual(JSON.stringify(findSenior(list2)),JSON.stringify([{ firstName: 'Gabriel', lastName: 'X.', country: 'Monaco', continent: 'Europe', age: 49, language:'PHP' }, { firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 49, language: 'PHP' }, { firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 49, language: 'PHP' }]));
- })});
function addArr(arr){ return arr.reduce((a,c) => a+c,0)||null; }
- function addArr(arr){
if(arr.length === 0) return nulllet final = 0arr.forEach(num => {final += num})return final- return arr.reduce((a,c) => a+c,0)||null;
- }
const chai = require("chai"); const assert = chai.assert; describe("Solution", function() { it("should test for something", function() { assert.strictEqual(addArr([1, 2, 3, 4, 5]), 15); assert.strictEqual(addArr([1, 100]), 101) assert.strictEqual(addArr([]), null) }); });
- const chai = require("chai");
- const assert = chai.assert;
- describe("Solution", function() {
- it("should test for something", function() {
- assert.strictEqual(addArr([1, 2, 3, 4, 5]), 15);
- assert.strictEqual(addArr([1, 100]), 101)
- assert.strictEqual(addArr([]), null)
- });
- });
function ShowDate() { const months = {'Jan':'January','Feb':'February','Mar':'March','Apr':'April','May':'May', 'Jun':'June','Jul':'July','Aug':'Augest','Sep':'September','Oct':'October', 'Nov':'November','Dec':'December'}; const days = {'1':'st','2':'nd','3':'rd'}; return new Date().toDateString().slice(4).split(' ').map((e,i) => i?i==1?+e+(days[e.slice(-1)]||'th'):e:months[e]).join(' '); }
- function ShowDate() {
const currentDate = new Date();const monthsOfYear = ["January","February","March","April","May","June","July","August","September","October","November","December",];const currentMonth = monthsOfYear[currentDate.getMonth()];const currentDay = currentDate.getDate();let daySuffix;switch (currentDay) {case 1:case 21:case 31:daySuffix = "st";break;case 2:case 22:daySuffix = "nd";break;case 3:case 23:daySuffix = "rd";break;default:daySuffix = "th";}const currentYear = currentDate.getFullYear();return `${currentMonth} ${currentDay}${daySuffix} ${currentYear}`;- const months = {'Jan':'January','Feb':'February','Mar':'March','Apr':'April','May':'May',
- 'Jun':'June','Jul':'July','Aug':'Augest','Sep':'September','Oct':'October',
- 'Nov':'November','Dec':'December'};
- const days = {'1':'st','2':'nd','3':'rd'};
- return new Date().toDateString().slice(4).split(' ').map((e,i) => i?i==1?+e+(days[e.slice(-1)]||'th'):e:months[e]).join(' ');
- }
Using replace method
const firstNonRepeatingCharacter = str => { const obj = [...str].reduce((a,c) => {a[c]?a[c]++:a[c]=1;return a},{}); return Object.keys(obj).find(e => obj[e]===1)||null; };
const firstNonRepeatingCharacter = (str) => {for (let i = 0; i < str.length; i++) {let seenDuplicate = false;for (let j = 0; j < str.length; j++) {if (str[i] === str[j] && i !== j) {seenDuplicate = true;break;}}if (!seenDuplicate) {return str[i];}}return null; // return null if no unique character is found- const firstNonRepeatingCharacter = str => {
- const obj = [...str].reduce((a,c) => {a[c]?a[c]++:a[c]=1;return a},{});
- return Object.keys(obj).find(e => obj[e]===1)||null;
- };
shorter code chars..
n=s=>[...s].map(e=>("aeiou".includes(e)?"aeiou".indexOf(e)+1:e)).join`` d=s=>[...s].map(e=>(+e&&e<6?"aeiou"[e-1]:e)).join``
- n=s=>[...s].map(e=>("aeiou".includes(e)?"aeiou".indexOf(e)+1:e)).join``
d=s=>[...s].map(e=>("12345".includes(e)?"aeiou"[e-1]:e)).join``- d=s=>[...s].map(e=>(+e&&e<6?"aeiou"[e-1]:e)).join``