Last active
March 11, 2016 13:45
-
-
Save conor909/af62f88aca615bd59225 to your computer and use it in GitHub Desktop.
file-name (1), file-name (2)
This file contains hidden or 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
const boxers = [ {name: "Muhammad Ali"}, {name: "Barry McGuigan"} ]; | |
const boxer = boxers[0]; | |
let clone = $.extend(true, {}, boxer); | |
let index = 1; | |
let isNameUnique = name => _(boxers) | |
.chain() | |
.map(dg => dg.name) | |
.all(n => n !== name) | |
.value(); | |
do { | |
clone.name = boxer.name + " (" + index + ")"; | |
index++; | |
} while (!isNameUnique(clone.name)); | |
console.log(clone.name); // Muhammad Ali (1), Muhammad Ali (2)... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment