Created
February 17, 2022 09:01
-
-
Save ca057/86137d44390e96851ba50ad60dd6927e to your computer and use it in GitHub Desktop.
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 padArrayEnd = <T>(arr: T[], targetLength: number, val: T): T[] => { | |
if (arr.length >= targetLength) return [...arr] | |
return arr.concat(Array(targetLength - arr.length).fill(val)) | |
} | |
console.log(padArrayEnd(["0", "1"], 3, "")) | |
console.log(padArrayEnd(["0", "1", "2"], 3, "")) | |
console.log(padArrayEnd(["0", "1", "2", "3"], 3, "")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment