Multiply a string by a number!
Jelly, 6 5 4 bytes
²Ɠxm
Try it online!
How it works
²Ɠxm Main link. Argument: n (integer)
² Yield n².
Ɠ Read and eval one line of input. This yields a string s.
x Repeat the characters of s in-place, each one n² times.
m Takes each |n|-th character of the result, starting with the first if n > 0,
the last if n < 0.
JavaScript (ES6), 63 bytes
Takes input in currying syntax (s)(n)
.
s=>n=>[...s].reduce((s,c)=>n<0?c.repeat(-n)+s:s+c.repeat(n),'')
Test cases
let f =
s=>n=>[...s].reduce((s,c)=>n<0?c.repeat(-n)+s:s+c.repeat(n),'')
console.log(f(`Hello World!`)(3))
console.log(f(`foo`)(12))
console.log(f(`String`)(-3))
console.log(f(`This is a fun challenge`)(0))
console.log(f(`Hello
World!`)(2))
Python 2, 59 57 50 46 bytes
-2 bytes thanks to Anders Kaseorg. -4 bytes thanks to Dennis.
lambda s,n:''.join(i*n**2for i in s)[::n or 1]
Try it online!