const isAnagram = (s1, s2) => s1.length === s2.length && Object.values([...s1].reduce((o, k, i) => (k in o ? ++o[k] : o[k] = 1, s2[i] in o ? --o[s2[i]] : o[s2[i]] = -1, o), {})).every(v => !v);
function isAnagram(str1, str2) {if (str1.length !== str2.length) {return false;}const frequency = {};for (let i = 0; i < str1.length; i++) {const char = str1[i];if (frequency[char]) {frequency[char]++;} else {frequency[char] = 1;}}for (let i = 0; i < str2.length; i++) {const char = str2[i];if (!frequency[char]) {return false;} else {frequency[char]--;}}return true;}- const isAnagram = (s1, s2) => s1.length === s2.length && Object.values([...s1].reduce((o, k, i) => (k in o ? ++o[k] : o[k] = 1, s2[i] in o ? --o[s2[i]] : o[s2[i]] = -1, o), {})).every(v => !v);
function capitalize(sentence) { return sentence.split(' ').map(w => w[0].toUpperCase() + w.slice(1)).join(' '); }
- function capitalize(sentence) {
let words = sentence.split(' ');const length = words.length;for (let i = 0; i < length; ++i) {words[i] = words[i][0].toUpperCase() + words[i].substr(1)}return words.join(' ');}console.log(capitalize("i am a javascript programmer"));- return sentence.split(' ').map(w => w[0].toUpperCase() + w.slice(1)).join(' ');
- }
const addArr = arr => arr.length ? arr.reduce((sum, num) => sum + num, 0) : null;
function addArr(arr){if(arr.length === 0) return nulllet final = 0arr.forEach(num => {final += num})return final}- const addArr = arr => arr.length ? arr.reduce((sum, num) => sum + num, 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)
- });
- });