Hello! My name is Thomas and I'm a nerd. I like tech and gadgets and speculative fiction, and playing around with programming. It's not my day job, but I'm working on making it a side gig :)
Nim supports specifying ranges both in absolute terms and in relative terms. ^2 would be the second to last position of a range, etc :) As you can see at the end of the procedure you can also supply just one end of the range and Nim will infer the other end, so filtered[^1] would be just the final element of the sequence.
importsequtils# for filterproc format_words(words:seq[string]):string=result=""ifwords.len>0:varfiltered=filter(words,proc(w:string):bool=w.len>0)forwordinfiltered[0..^2]:result.add(word&", ")returnresult[0..^3]&(" and "&filtered[^1])echoformat_words(@["ninja","samurai","ronin","leonardo","michelangelo","donatello","raphael"])echoformat_words(@["ninja","samurai","ronin"])echoformat_words(@["ninja","","ronin"])echoformat_words(@[])
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
My Nim solution :)
Nim supports specifying ranges both in absolute terms and in relative terms. ^2 would be the second to last position of a range, etc :) As you can see at the end of the procedure you can also supply just one end of the range and Nim will infer the other end, so filtered[^1] would be just the final element of the sequence.