Created
November 3, 2021 11:28
-
-
Save ChrisRoss5/1250176f2c73fee8b49b0433d4e6db2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function z1(l: number[]) { | |
if (!l.length) return []; | |
return [ | |
l.reduce((a, b) => a + (b > 0 ? b : 0), 0), | |
l.reduce((a, b) => a + (b < 0 ? b : 0), 0), | |
]; | |
} | |
function z2(s: string) { | |
return [...new Set(s.split(" "))].join(" "); | |
} | |
function z3(s: string) { | |
const letters = "abcčćddžđefghijkljmnjoprsštuvzž"; | |
const words = s.split(new RegExp(`[^${letters}]`, "g")); | |
const scores = words.map((word) => | |
[...word].reduce((a, b) => a + letters.indexOf(b) + 1, 0) | |
); | |
return words[scores.indexOf(Math.max(...scores))]; | |
} | |
console.log(z1([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15])); | |
console.log(z2("alpha beta gamma delta alpha beta beta gamma delta")); | |
console.log(z3("abc-def.ghi uvzž,jklmn+žzvu")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment