Ad
Code
Diff
  • SELECT * FROM employees WHERE salary>5000000 AND months>=12 ORDER BY salary DESC;
    • SELECT *
    • FROM employees emp
    • WHERE emp.salary>5000000 AND emp.months>=12
    • ORDER BY emp.salary DESC
    • SELECT * FROM employees WHERE salary>5000000 AND months>=12 ORDER BY salary DESC;
Code
Diff
  • XOR=(a,b)=>!!(a-b)
    • XOR=(a,b)=>!!((a+b)%2)
    • XOR=(a,b)=>!!(a-b)

In case of numbers that exceeds Number.MAX_SAFE_INTEGER (2^53 - 1), those numbers in js MUST be passed as Big integers to avoid precision loss

Code
Diff
  • const maxNumber = n => {
      return BigInt([...n+''].reduce((a,c) => {a[9-c]=(a[9-c]||'')+c;return a},[]).join(''));
    }
    • import java.util.Arrays;
    • public class MaxNumber {
    • public static long print(long number) {
    • return number
    • }
    • const maxNumber = n => {
    • return BigInt([...n+''].reduce((a,c) => {a[9-c]=(a[9-c]||'')+c;return a},[]).join(''));
    • }
Code
Diff
  • function mean(x){
      return x.length? x.reduce((a,c) => a+c,0)/x.length : 0;
    }
    • #include <iostream>
    • double Mean(double x[], int n){
    • double sum = 0;
    • for(int i = 0; i < n; i++){
    • sum += x[i];
    • }
    • return sum / n;
    • function mean(x){
    • return x.length? x.reduce((a,c) => a+c,0)/x.length : 0;
    • }
Code
Diff
  • function missingNumber(arr){
      const max = Math.max(...arr);
      return (max*(max+1)/2)-arr.reduce((a,c) => a+c,0);
    }
    • class Solution {
    • public:
    • int missingNumber(vector<int>& nums) {
    • }
    • };
    • function missingNumber(arr){
    • const max = Math.max(...arr);
    • return (max*(max+1)/2)-arr.reduce((a,c) => a+c,0);
    • }

js version with fixed TestCases.

Code
Diff
  • 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');
    • }

~ Fixed TestCases ~

Code
Diff
  • 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 sviluppatori
    • if (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);
    • }
Code
Diff
  • function formatIfNumber(value, numberOfPlaces) {
      return value===+value?+value.toFixed(numberOfPlaces):value;
    }
    • function formatIfNumber(value, numberOfPlaces) {
    • return "";
    • return value===+value?+value.toFixed(numberOfPlaces):value;
    • }
Code
Diff
  • function addArr(arr){
      return arr.reduce((a,c) => a+c,0)||null;
    }
    • function addArr(arr){
    • if(arr.length === 0) return null
    • let final = 0
    • arr.forEach(num => {
    • final += num
    • })
    • return final
    • return arr.reduce((a,c) => a+c,0)||null;
    • }
Date Time
Code
Diff
  • 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

Code
Diff
  • g=w=>w.replace(/./g,(x,i)=>w[w.length-1-i])
    • function reverseGear(word){
    • //put your code here
    • }
    • g=w=>w.replace(/./g,(x,i)=>w[w.length-1-i])
Code
Diff
  • function numMinusSeven(num) {
      return Math.ceil(num/7);
    }
    
    • function numMinusSeven(num) {
    • let arr = []
    • while (num > 0) {
    • num -= 7
    • arr.push(num)
    • }
    • return arr.length
    • return Math.ceil(num/7);
    • }
Code
Diff
  • 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..

Code
Diff
  • 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``