Skip to content

Instantly share code, notes, and snippets.

@gustavoFreireS
Last active July 6, 2023 14:25
Show Gist options
  • Save gustavoFreireS/da33ef0881ae2192f981540af79f55c2 to your computer and use it in GitHub Desktop.
Save gustavoFreireS/da33ef0881ae2192f981540af79f55c2 to your computer and use it in GitHub Desktop.
bugged test
/*
given a string of colors separated by a blank space like so: "red2 blue5 black4 green1 gold3" return another string with the colors ordered by the number it ends with
ex:
input: red2 blue5 black4 green1 gold3
output: green red gold black blue
*/
var solution = function (s) {
// write your solution here
const listColors = s.split(" ");
let ans = [...listColors];
for (let i = 0; i < listColors.length; i++) {
let last = listColors[i].length - 1;
const number = listColors[i][last];
ans[number - 1] = listColors[i].substring(0, last);
}
return ans.join(' ');
};
// do not write on this line, this will be used to evaluate the question
// tinha isso mas vou mudar pq dá trabalho copiar e colar toda vida
// const readline = require("readline").createInterface({
// input: process.stdin,
// output: process.stdout,
// });
// readline.question("", (prompt) => {
// console.log(solution(prompt));
// readline.close();
// });
console.log(solution("red2 blue5 black4 green1 gold3"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment